ReactOS 0.4.17-dev-966-gf06eace
glsl_shader.c File Reference
#include <limits.h>
#include <stdio.h>
#include "wined3d_private.h"
#include "wined3d_gl.h"
Include dependency graph for glsl_shader.c:

Go to the source code of this file.

Classes

struct  glsl_dst_param
 
struct  glsl_src_param
 
struct  glsl_sample_function
 
struct  constant_entry
 
struct  constant_heap
 
struct  shader_glsl_priv
 
struct  glsl_vs_program
 
struct  glsl_hs_program
 
struct  glsl_ds_program
 
struct  glsl_gs_program
 
struct  glsl_ps_program
 
struct  glsl_cs_program
 
struct  glsl_shader_prog_link
 
struct  glsl_program_key
 
struct  shader_glsl_ctx_priv
 
struct  glsl_context_data
 
struct  glsl_ps_compiled_shader
 
struct  glsl_vs_compiled_shader
 
struct  glsl_hs_compiled_shader
 
struct  glsl_ds_compiled_shader
 
struct  glsl_gs_compiled_shader
 
struct  glsl_cs_compiled_shader
 
struct  glsl_shader_private
 
struct  glsl_ffp_vertex_shader
 
struct  glsl_ffp_fragment_shader
 
struct  glsl_ffp_destroy_ctx
 
struct  glsl_blitter_args
 
struct  glsl_blitter_program
 
struct  wined3d_glsl_blitter
 

Macros

#define WINED3D_GLSL_SAMPLE_PROJECTED   0x01
 
#define WINED3D_GLSL_SAMPLE_LOD   0x02
 
#define WINED3D_GLSL_SAMPLE_GRAD   0x04
 
#define WINED3D_GLSL_SAMPLE_LOAD   0x08
 
#define WINED3D_GLSL_SAMPLE_OFFSET   0x10
 
#define WINED3D_TO_STR(u)   case u: return #u
 

Enumerations

enum  heap_node_op { HEAP_NODE_TRAVERSE_LEFT , HEAP_NODE_TRAVERSE_RIGHT , HEAP_NODE_POP }
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (d3d_shader)
 
 WINE_DECLARE_DEBUG_CHANNEL (d3d)
 
 WINE_DECLARE_DEBUG_CHANNEL (winediag)
 
static void shader_glsl_generate_shader_epilogue (const struct wined3d_shader_context *ctx)
 
static const char * debug_gl_shader_type (GLenum type)
 
static const char * shader_glsl_get_prefix (enum wined3d_shader_type type)
 
static unsigned int shader_glsl_get_version (const struct wined3d_gl_info *gl_info)
 
static void shader_glsl_add_version_declaration (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info)
 
static unsigned int shader_glsl_full_ffp_varyings (const struct wined3d_gl_info *gl_info)
 
static void shader_glsl_append_imm_vec (struct wined3d_string_buffer *buffer, const float *values, unsigned int size, const struct wined3d_gl_info *gl_info)
 
static void shader_glsl_append_imm_ivec (struct wined3d_string_buffer *buffer, const int *values, unsigned int size)
 
void print_glsl_info_log (const struct wined3d_gl_info *gl_info, GLuint id, BOOL program)
 
static void shader_glsl_compile (const struct wined3d_gl_info *gl_info, GLuint shader, const char *src)
 
static void shader_glsl_dump_program_source (const struct wined3d_gl_info *gl_info, GLuint program)
 
void shader_glsl_validate_link (const struct wined3d_gl_info *gl_info, GLuint program)
 
static struct vkd3d_shader_resource_binding * create_resource_bindings (const struct wined3d_gl_info *gl_info, enum wined3d_shader_type shader_type, unsigned int *count)
 
static struct vkd3d_shader_combined_resource_sampler * create_combined_resource_sampler_bindings (const struct wined3d_context_gl *context_gl, const struct wined3d_shader *shader, unsigned int *count)
 
static GLuint shader_glsl_generate_vkd3d_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader, GLenum gl_shader_type)
 
static BOOL shader_glsl_use_layout_qualifier (const struct wined3d_gl_info *gl_info)
 
static BOOL shader_glsl_use_layout_binding_qualifier (const struct wined3d_gl_info *gl_info)
 
static void shader_glsl_init_uniform_block_bindings (const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, const struct wined3d_shader_reg_maps *reg_maps)
 
static void shader_glsl_load_samplers_range (const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, const char *prefix, unsigned int base, unsigned int count, const unsigned int *tex_unit_map)
 
static unsigned int shader_glsl_map_tex_unit (const struct wined3d_context *context, const struct wined3d_shader_version *shader_version, unsigned int sampler_idx)
 
static void shader_glsl_append_sampler_binding_qualifier (struct wined3d_string_buffer *buffer, const struct wined3d_context *context, const struct wined3d_shader_version *shader_version, unsigned int sampler_idx)
 
static void shader_glsl_load_samplers (const struct wined3d_context *context, struct shader_glsl_priv *priv, GLuint program_id, const struct wined3d_shader_reg_maps *reg_maps)
 
static void shader_glsl_load_icb (const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, const struct wined3d_shader_reg_maps *reg_maps)
 
static void shader_glsl_load_images (const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, const struct wined3d_shader_reg_maps *reg_maps)
 
static void shader_glsl_load_program_resources (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, GLuint program_id, const struct wined3d_shader *shader)
 
static void append_transform_feedback_varying (const char **varyings, unsigned int *varying_count, char **strings, unsigned int *strings_length, struct wined3d_string_buffer *buffer)
 
static void append_transform_feedback_skip_components (const char **varyings, unsigned int *varying_count, char **strings, unsigned int *strings_length, struct wined3d_string_buffer *buffer, unsigned int component_count)
 
static BOOL shader_glsl_generate_transform_feedback_varyings (struct wined3d_string_buffer *buffer, const char **varyings, unsigned int *varying_count, char *strings, unsigned int *strings_length, GLenum buffer_mode, struct wined3d_shader *shader)
 
static void shader_glsl_init_transform_feedback (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, GLuint program_id, struct wined3d_shader *shader)
 
static void walk_constant_heap (const struct wined3d_gl_info *gl_info, const struct wined3d_vec4 *constants, const GLint *constant_locations, const struct constant_heap *heap, unsigned char *stack, DWORD version)
 
static void apply_clamped_constant (const struct wined3d_gl_info *gl_info, GLint location, const struct wined3d_vec4 *data)
 
static void walk_constant_heap_clamped (const struct wined3d_gl_info *gl_info, const struct wined3d_vec4 *constants, const GLint *constant_locations, const struct constant_heap *heap, unsigned char *stack, DWORD version)
 
static void shader_glsl_load_constants_f (const struct wined3d_shader *shader, struct wined3d_context_gl *context_gl, struct wined3d_buffer *constant_buffer, const GLint *constant_locations, const struct constant_heap *heap, unsigned char *stack, unsigned int version)
 
static void shader_glsl_load_constants_i (const struct wined3d_shader *shader, struct wined3d_context_gl *context_gl, struct wined3d_buffer *constant_buffer, const GLint locations[WINED3D_MAX_CONSTS_I], uint32_t constants_set)
 
static void shader_glsl_load_constants_b (const struct wined3d_shader *shader, struct wined3d_context_gl *context_gl, struct wined3d_buffer *constant_buffer, const GLint locations[WINED3D_MAX_CONSTS_B], uint32_t constants_set)
 
static void reset_program_constant_version (struct wine_rb_entry *entry, void *context)
 
static void get_projection_matrix (const struct wined3d_context *context, const struct wined3d_ffp_vs_constants *constants, const struct wined3d_state *state, struct wined3d_matrix *mat)
 
static void shader_glsl_ffp_vertex_normalmatrix_uniform (const struct wined3d_context_gl *context_gl, const struct wined3d_ffp_vs_constants *constants, struct glsl_shader_prog_link *prog)
 
static void shader_glsl_ffp_vertex_texmatrix_uniform (const struct wined3d_context_gl *context_gl, const struct wined3d_ffp_vs_constants *constants, unsigned int tex, struct glsl_shader_prog_link *prog)
 
static void shader_glsl_ffp_vertex_material_uniform (struct wined3d_context_gl *context_gl, const struct wined3d_state *state, struct glsl_shader_prog_link *prog)
 
static void shader_glsl_ffp_vertex_light_uniform (const struct wined3d_context_gl *context_gl, const struct wined3d_state *state, unsigned int light, enum wined3d_light_type type, const struct wined3d_light_constants *constants, struct glsl_shader_prog_link *prog)
 
static void shader_glsl_pointsize_uniform (struct wined3d_context_gl *context_gl, const struct wined3d_state *state, struct glsl_shader_prog_link *prog)
 
static void shader_glsl_load_fog_uniform (const struct wined3d_context_gl *context_gl, const struct wined3d_state *state, struct glsl_shader_prog_link *prog)
 
static void shader_glsl_clip_plane_uniform (const struct wined3d_context_gl *context_gl, const struct wined3d_state *state, unsigned int index, struct glsl_shader_prog_link *prog)
 
static void shader_glsl_load_constants (struct shader_glsl_priv *priv, struct wined3d_context *context, const struct wined3d_state *state)
 
static void update_heap_entry (struct constant_heap *heap, unsigned int idx, DWORD new_version)
 
static void shader_glsl_update_float_vertex_constants (struct wined3d_device *device, UINT start, UINT count)
 
static void shader_glsl_update_float_pixel_constants (struct wined3d_device *device, UINT start, UINT count)
 
static unsigned int vec4_varyings (DWORD shader_major, const struct wined3d_gl_info *gl_info)
 
static BOOL needs_legacy_glsl_syntax (const struct wined3d_gl_info *gl_info)
 
static BOOL shader_glsl_use_explicit_attrib_location (const struct wined3d_gl_info *gl_info)
 
static BOOL shader_glsl_use_interface_blocks (const struct wined3d_gl_info *gl_info)
 
static const char * get_attribute_keyword (const struct wined3d_gl_info *gl_info)
 
static void PRINTF_ATTR (4, 5)
 
static const char * shader_glsl_shader_input_name (const struct wined3d_gl_info *gl_info)
 
static const char * shader_glsl_shader_output_name (const struct wined3d_gl_info *gl_info)
 
static const char * shader_glsl_interpolation_qualifiers (enum wined3d_shader_interpolation_mode mode)
 
static enum wined3d_shader_interpolation_mode wined3d_extract_interpolation_mode (const uint32_t *packed_interpolation_mode, unsigned int register_idx)
 
static void shader_glsl_declare_shader_inputs (const struct wined3d_gl_info *gl_info, struct wined3d_string_buffer *buffer, unsigned int element_count, const uint32_t *interpolation_mode, BOOL unroll)
 
static BOOL needs_interpolation_qualifiers_for_shader_outputs (const struct wined3d_gl_info *gl_info)
 
static void shader_glsl_declare_shader_outputs (const struct wined3d_gl_info *gl_info, struct wined3d_string_buffer *buffer, unsigned int element_count, BOOL rasterizer_setup, const uint32_t *interpolation_mode)
 
static BOOL use_legacy_fragment_output (const struct wined3d_gl_info *gl_info)
 
static const char * get_fragment_output (const struct wined3d_gl_info *gl_info)
 
static const char * glsl_primitive_type_from_d3d (enum wined3d_primitive_type primitive_type)
 
static BOOL glsl_is_color_reg_read (const struct wined3d_shader *shader, unsigned int idx)
 
static void shader_glsl_declare_typed_vertex_attribute (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const char *vector_type, const char *scalar_type, unsigned int index)
 
static void shader_glsl_declare_generic_vertex_attribute (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const struct wined3d_shader_signature_element *e)
 
static void shader_generate_glsl_declarations (const struct wined3d_context_gl *context_gl, struct wined3d_string_buffer *buffer, const struct wined3d_shader *shader, const struct wined3d_shader_reg_maps *reg_maps, const struct shader_glsl_ctx_priv *ctx_priv)
 
static void shader_glsl_add_src_param_ext (const struct wined3d_shader_context *ctx, const struct wined3d_shader_src_param *wined3d_src, DWORD mask, struct glsl_src_param *glsl_src, enum wined3d_data_type data_type)
 
static void shader_glsl_gen_modifier (enum wined3d_shader_src_modifier src_modifier, const char *in_reg, const char *in_regswizzle, char *out_str)
 
static void shader_glsl_fixup_scalar_register_variable (struct wined3d_string_buffer *register_name, const char *glsl_variable, const struct wined3d_gl_info *gl_info)
 
static void shader_glsl_get_register_name (const struct wined3d_shader_register *reg, enum wined3d_data_type data_type, struct wined3d_string_buffer *register_name, BOOL *is_swizzled, const struct wined3d_shader_context *ctx)
 
static void shader_glsl_write_mask_to_str (DWORD write_mask, char *str)
 
static DWORD shader_glsl_get_write_mask (const struct wined3d_shader_dst_param *param, char *write_mask)
 
static unsigned int shader_glsl_get_write_mask_size (DWORD write_mask)
 
static unsigned int shader_glsl_swizzle_get_component (DWORD swizzle, unsigned int component_idx)
 
static void shader_glsl_swizzle_to_str (DWORD swizzle, BOOL fixup, DWORD mask, char *str)
 
static void shader_glsl_get_swizzle (const struct wined3d_shader_src_param *param, BOOL fixup, DWORD mask, char *swizzle_str)
 
static void shader_glsl_sprintf_cast (struct wined3d_string_buffer *dst_param, const char *src_param, enum wined3d_data_type dst_data_type, enum wined3d_data_type src_data_type, unsigned int size)
 
static void shader_glsl_add_src_param (const struct wined3d_shader_instruction *ins, const struct wined3d_shader_src_param *wined3d_src, DWORD mask, struct glsl_src_param *glsl_src)
 
static DWORD shader_glsl_add_dst_param (const struct wined3d_shader_instruction *ins, const struct wined3d_shader_dst_param *wined3d_dst, struct glsl_dst_param *glsl_dst)
 
static DWORD shader_glsl_append_dst_ext (struct wined3d_string_buffer *buffer, const struct wined3d_shader_instruction *ins, const struct wined3d_shader_dst_param *dst, unsigned int dst_idx, enum wined3d_data_type data_type)
 
static DWORD shader_glsl_append_dst (struct wined3d_string_buffer *buffer, const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_add_instruction_modifiers (const struct wined3d_shader_instruction *ins)
 
static const char * shader_glsl_get_rel_op (enum wined3d_shader_rel_op op)
 
static BOOL shader_glsl_has_core_grad (const struct wined3d_gl_info *gl_info)
 
static void shader_glsl_get_coord_size (enum wined3d_shader_resource_type resource_type, unsigned int *coord_size, unsigned int *deriv_size)
 
static void shader_glsl_get_sample_function (const struct wined3d_shader_context *ctx, DWORD resource_idx, DWORD sampler_idx, uint32_t flags, struct glsl_sample_function *sample_function)
 
static void shader_glsl_release_sample_function (const struct wined3d_shader_context *ctx, struct glsl_sample_function *sample_function)
 
static void shader_glsl_append_fixup_arg (char *arguments, const char *reg_name, BOOL sign_fixup, enum fixup_channel_source channel_source)
 
static void shader_glsl_color_correction_ext (struct wined3d_string_buffer *buffer, const char *reg_name, DWORD mask, struct color_fixup_desc fixup)
 
static void shader_glsl_color_correction (const struct wined3d_shader_instruction *ins, struct color_fixup_desc fixup)
 
static void PRINTF_ATTR (9, 10)
 
static void shader_glsl_fixup_position (struct wined3d_string_buffer *buffer, BOOL use_viewport_index)
 
static void shader_glsl_binop (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_relop (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_unary_op (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_mul_extended (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_udiv (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_mov (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_dot (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_cross (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_cut (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_pow (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_map2gl (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_float16 (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_bitwise_op (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_nop (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_nrm (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_scalar_op (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_expp (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_cast (const struct wined3d_shader_instruction *ins, const char *vector_constructor, const char *scalar_constructor)
 
static void shader_glsl_to_int (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_to_uint (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_to_float (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_compare (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_swapc (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_conditional_move (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_cnd (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_mad (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_mnxn (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_lrp (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_lit (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_dst (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_sincos (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_sgn (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_loop (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_end (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_rep (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_switch (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_case (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_default (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_generate_condition (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_if (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_ifc (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_else (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_emit (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_break (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_breakc (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_conditional_op (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_continue (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_label (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_call (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_callnz (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_ret (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_tex (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texldd (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texldl (const struct wined3d_shader_instruction *ins)
 
static unsigned int shader_glsl_find_sampler (const struct wined3d_shader_sampler_map *sampler_map, unsigned int resource_idx, unsigned int sampler_idx)
 
static void shader_glsl_atomic (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_uav_counter (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_ld_uav (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_ld_raw_structured (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_store_uav (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_store_raw_structured (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_sync (const struct wined3d_shader_instruction *ins)
 
static const struct wined3d_shader_resource_info * shader_glsl_get_resource_info (const struct wined3d_shader_instruction *ins, const struct wined3d_shader_register *reg)
 
static void shader_glsl_bufinfo (const struct wined3d_shader_instruction *ins)
 
static BOOL is_multisampled (enum wined3d_shader_resource_type resource_type)
 
static BOOL is_mipmapped (enum wined3d_shader_resource_type resource_type)
 
static void shader_glsl_resinfo (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_sample_info (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_interpolate (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_ld (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_sample (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_gen_sample_c_lz_emulation (const struct wined3d_shader_instruction *ins, unsigned int sampler_bind_idx, const struct glsl_sample_function *sample_function, unsigned int coord_size, const char *coord_param, const char *ref_param)
 
static void shader_glsl_sample_c (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_gather4 (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texcoord (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texdp3tex (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texdp3 (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texdepth (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texm3x2depth (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texm3x2pad (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texm3x3pad (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texm3x2tex (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texm3x3tex (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texm3x3 (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texm3x3spec (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texm3x3vspec (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texbem (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_bem (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texreg2ar (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texreg2gb (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texreg2rgb (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_texkill (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_dp2add (const struct wined3d_shader_instruction *ins)
 
static void shader_glsl_input_pack (const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer, const struct wined3d_shader_signature *input_signature, const struct wined3d_shader_reg_maps *reg_maps, const struct ps_compile_args *args, const struct wined3d_gl_info *gl_info, BOOL unroll)
 
static void add_glsl_program_entry (struct shader_glsl_priv *priv, struct glsl_shader_prog_link *entry)
 
static struct glsl_shader_prog_link * get_glsl_program_entry (const struct shader_glsl_priv *priv, const struct glsl_program_key *key)
 
static void delete_glsl_program_entry (struct shader_glsl_priv *priv, const struct wined3d_gl_info *gl_info, struct glsl_shader_prog_link *entry)
 
static void shader_glsl_setup_vs3_output (struct shader_glsl_priv *priv, const struct wined3d_gl_info *gl_info, const unsigned int *map, const struct wined3d_shader_signature *input_signature, const struct wined3d_shader_reg_maps *reg_maps_in, const struct wined3d_shader_signature *output_signature, const struct wined3d_shader_reg_maps *reg_maps_out)
 
static void shader_glsl_setup_sm4_shader_output (struct shader_glsl_priv *priv, unsigned int input_count, const struct wined3d_shader_signature *output_signature, const struct wined3d_shader_reg_maps *reg_maps_out, const char *output_variable_name, BOOL rasterizer_setup)
 
static void shader_glsl_generate_clip_or_cull_distances (struct wined3d_string_buffer *buffer, const struct wined3d_shader_signature_element *element, DWORD clip_or_cull_distance_mask)
 
static void shader_glsl_setup_sm3_rasterizer_input (struct shader_glsl_priv *priv, const struct wined3d_gl_info *gl_info, const unsigned int *map, const struct wined3d_shader_signature *input_signature, const struct wined3d_shader_reg_maps *reg_maps_in, unsigned int input_count, const struct wined3d_shader_signature *output_signature, const struct wined3d_shader_reg_maps *reg_maps_out, BOOL per_vertex_point_size)
 
static GLuint shader_glsl_generate_vs3_rasterizer_input_setup (struct shader_glsl_priv *priv, const struct wined3d_shader *vs, const struct wined3d_shader *ps, BOOL per_vertex_point_size, BOOL flatshading, const struct wined3d_gl_info *gl_info)
 
static void shader_glsl_generate_stream_output_setup (struct wined3d_string_buffer *buffer, const struct wined3d_shader *shader)
 
static void shader_glsl_generate_sm4_output_setup (struct shader_glsl_priv *priv, const struct wined3d_shader *shader, unsigned int input_count, const struct wined3d_gl_info *gl_info, BOOL rasterizer_setup, const uint32_t *interpolation_mode)
 
static void shader_glsl_generate_patch_constant_name (struct wined3d_string_buffer *buffer, const struct wined3d_shader_signature_element *constant, unsigned int *user_constant_idx, const char *reg_mask)
 
static void shader_glsl_generate_patch_constant_setup (struct wined3d_string_buffer *buffer, const struct wined3d_shader_signature *signature, BOOL input_setup)
 
static void shader_glsl_generate_srgb_write_correction (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info)
 
static void shader_glsl_generate_fog_code (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, enum wined3d_ffp_ps_fog_mode mode)
 
static void shader_glsl_generate_alpha_test (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, enum wined3d_cmp_func alpha_func)
 
static void shader_glsl_generate_colour_key_test (struct wined3d_string_buffer *buffer, const char *colour, const char *colour_key_low, const char *colour_key_high)
 
static void shader_glsl_enable_extensions (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info)
 
static void shader_glsl_generate_color_output (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const struct wined3d_shader *shader, const struct ps_compile_args *args, struct wined3d_string_buffer_list *string_buffers)
 
static void shader_glsl_generate_ps_epilogue (const struct wined3d_gl_info *gl_info, struct wined3d_string_buffer *buffer, const struct wined3d_shader *shader, const struct ps_compile_args *args, struct wined3d_string_buffer_list *string_buffers)
 
static GLuint shader_glsl_generate_fragment_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader, const struct ps_compile_args *args)
 
static void shader_glsl_generate_vs_epilogue (const struct wined3d_gl_info *gl_info, struct wined3d_string_buffer *buffer, const struct wined3d_shader *shader, const struct vs_compile_args *args)
 
static GLuint shader_glsl_generate_vertex_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader, const struct vs_compile_args *args)
 
static void shader_glsl_generate_default_control_point_phase (const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer, const struct wined3d_shader_reg_maps *reg_maps)
 
static HRESULT shader_glsl_generate_shader_phase (const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer, const struct wined3d_shader_reg_maps *reg_maps, struct shader_glsl_ctx_priv *priv_ctx, const struct wined3d_shader_phase *phase, const char *phase_name, unsigned phase_idx)
 
static void shader_glsl_generate_shader_phase_invocation (struct wined3d_string_buffer *buffer, const struct wined3d_shader_phase *phase, const char *phase_name, unsigned int phase_idx)
 
static GLuint shader_glsl_generate_hull_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader)
 
static void shader_glsl_generate_ds_epilogue (const struct wined3d_gl_info *gl_info, struct wined3d_string_buffer *buffer, const struct wined3d_shader *shader, const struct ds_compile_args *args)
 
static GLuint shader_glsl_generate_domain_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader, const struct ds_compile_args *args)
 
static GLuint shader_glsl_generate_geometry_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader, const struct gs_compile_args *args)
 
static GLuint shader_glsl_generate_compute_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader)
 
static GLuint find_glsl_fragment_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, struct wined3d_shader *shader, const struct ps_compile_args *args)
 
static BOOL vs_args_equal (const struct vs_compile_args *stored, const struct vs_compile_args *new, const DWORD use_map)
 
static GLuint find_glsl_vertex_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, struct wined3d_shader *shader, const struct vs_compile_args *args)
 
static GLuint find_glsl_hull_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, struct wined3d_shader *shader)
 
static GLuint find_glsl_domain_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, struct wined3d_shader *shader, const struct ds_compile_args *args)
 
static GLuint find_glsl_geometry_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, struct wined3d_shader *shader, const struct gs_compile_args *args)
 
static const char * shader_glsl_ffp_mcs (enum wined3d_material_color_source mcs, const char *material)
 
static void shader_glsl_ffp_vertex_lighting_footer (struct wined3d_string_buffer *buffer, const struct wined3d_ffp_vs_settings *settings, unsigned int idx, BOOL legacy_lighting)
 
static void shader_glsl_ffp_vertex_lighting (struct wined3d_string_buffer *buffer, const struct wined3d_ffp_vs_settings *settings, BOOL legacy_lighting)
 
static GLuint shader_glsl_generate_ffp_vertex_shader (struct shader_glsl_priv *priv, const struct wined3d_ffp_vs_settings *settings, const struct wined3d_gl_info *gl_info)
 
static const char * shader_glsl_get_ffp_fragment_op_arg (struct wined3d_string_buffer *buffer, unsigned int argnum, unsigned int stage, DWORD arg)
 
static void shader_glsl_ffp_fragment_op (struct wined3d_string_buffer *buffer, unsigned int stage, BOOL color, BOOL alpha, BOOL tmp_dst, unsigned int op, DWORD dw_arg0, DWORD dw_arg1, DWORD dw_arg2)
 
static GLuint shader_glsl_generate_ffp_fragment_shader (struct shader_glsl_priv *priv, const struct ffp_frag_settings *settings, const struct wined3d_context_gl *context_gl)
 
static struct glsl_ffp_vertex_shader * shader_glsl_find_ffp_vertex_shader (struct shader_glsl_priv *priv, const struct wined3d_gl_info *gl_info, const struct wined3d_ffp_vs_settings *settings)
 
static struct glsl_ffp_fragment_shader * shader_glsl_find_ffp_fragment_shader (struct shader_glsl_priv *priv, const struct ffp_frag_settings *args, const struct wined3d_context_gl *context_gl)
 
static void shader_glsl_init_vs_uniform_locations (const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, struct glsl_vs_program *vs, unsigned int vs_c_count)
 
static void shader_glsl_init_ds_uniform_locations (const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, struct glsl_ds_program *ds)
 
static void shader_glsl_init_gs_uniform_locations (const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, struct glsl_gs_program *gs)
 
static void shader_glsl_init_ps_uniform_locations (const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, struct glsl_ps_program *ps, unsigned int ps_c_count)
 
static HRESULT shader_glsl_compile_compute_shader (struct shader_glsl_priv *priv, const struct wined3d_context_gl *context_gl, struct wined3d_shader *shader)
 
static GLuint find_glsl_compute_shader (const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, struct wined3d_shader *shader)
 
static void set_glsl_compute_shader_program (const struct wined3d_context_gl *context_gl, const struct wined3d_state *state, struct shader_glsl_priv *priv, struct glsl_context_data *ctx_data)
 
static void set_glsl_shader_program (const struct wined3d_context_gl *context_gl, const struct wined3d_state *state, struct shader_glsl_priv *priv, struct glsl_context_data *ctx_data)
 
static void shader_glsl_precompile (void *shader_priv, struct wined3d_shader *shader)
 
static void shader_glsl_update_graphics_program (struct shader_glsl_priv *priv, struct wined3d_context_gl *context_gl, const struct wined3d_state *state)
 
static void shader_glsl_update_legacy_states (struct wined3d_context_gl *context_gl, const struct wined3d_state *state)
 
static void shader_glsl_apply_draw_state (void *shader_priv, struct wined3d_context *context, const struct wined3d_state *state)
 
static void shader_glsl_update_compute_program (struct shader_glsl_priv *priv, struct wined3d_context_gl *context_gl, const struct wined3d_state *state)
 
static void shader_glsl_apply_compute_state (void *shader_priv, struct wined3d_context *context, const struct wined3d_state *state)
 
static void shader_glsl_invalidate_current_program (struct wined3d_context *context)
 
static void shader_glsl_disable (void *shader_priv, struct wined3d_context *context)
 
static void shader_glsl_invalidate_contexts_program (struct wined3d_device *device, const struct glsl_shader_prog_link *program)
 
static void shader_glsl_destroy (struct wined3d_shader *shader)
 
static int glsl_program_key_compare (const void *key, const struct wine_rb_entry *entry)
 
static BOOL constant_heap_init (struct constant_heap *heap, unsigned int constant_count)
 
static void constant_free (struct constant_heap *heap)
 
static HRESULT shader_glsl_alloc (struct wined3d_device *device, const struct wined3d_vertex_pipe_ops *vertex_pipe, const struct wined3d_fragment_pipe_ops *fragment_pipe)
 
static void shader_glsl_free (struct wined3d_device *device, struct wined3d_context *context)
 
static BOOL shader_glsl_allocate_context_data (struct wined3d_context *context)
 
static void shader_glsl_free_context_data (struct wined3d_context *context)
 
static void shader_glsl_init_context_state (struct wined3d_context *context)
 
static unsigned int shader_glsl_get_shader_model (const struct wined3d_gl_info *gl_info)
 
static void shader_glsl_get_caps (const struct wined3d_adapter *adapter, struct shader_caps *caps)
 
static BOOL shader_glsl_color_fixup_supported (struct color_fixup_desc fixup)
 
static void shader_glsl_handle_instruction (const struct wined3d_shader_instruction *ins)
 
static uint64_t shader_glsl_shader_compile (struct wined3d_context *context, const struct wined3d_shader_desc *shader_desc, enum wined3d_shader_type shader_type)
 
static void glsl_vertex_pipe_vp_apply_draw_state (struct wined3d_context *context, const struct wined3d_state *state)
 
static void glsl_vertex_pipe_vp_disable (const struct wined3d_context *context)
 
static void glsl_vertex_pipe_vp_get_caps (const struct wined3d_adapter *adapter, struct wined3d_vertex_caps *caps)
 
static unsigned int glsl_vertex_pipe_vp_get_emul_mask (const struct wined3d_adapter *adapter)
 
static void * glsl_vertex_pipe_vp_alloc (const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
 
static void shader_glsl_free_ffp_vertex_shader (struct wine_rb_entry *entry, void *param)
 
static void glsl_vertex_pipe_vp_free (struct wined3d_device *device, struct wined3d_context *context)
 
static void glsl_vertex_pipe_nop (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_vertex_pipe_shader (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_vertex_pipe_vdecl (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_vertex_pipe_vs (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_vertex_pipe_hs (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_vertex_pipe_geometry_shader (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_vertex_pipe_pixel_shader (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_vertex_pipe_viewport (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_vertex_pipe_pointsize (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_vertex_pipe_shademode (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_vertex_pipe_clip_plane (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_fragment_pipe_apply_draw_state (struct wined3d_context *context, const struct wined3d_state *state)
 
static void glsl_fragment_pipe_disable (const struct wined3d_context *context)
 
static void glsl_fragment_pipe_get_caps (const struct wined3d_adapter *adapter, struct fragment_caps *caps)
 
static unsigned int glsl_fragment_pipe_get_emul_mask (const struct wined3d_adapter *adapter)
 
static void * glsl_fragment_pipe_alloc (const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
 
static void shader_glsl_free_ffp_fragment_shader (struct wine_rb_entry *entry, void *param)
 
static void glsl_fragment_pipe_free (struct wined3d_device *device, struct wined3d_context *context)
 
static void glsl_fragment_pipe_shader (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_fragment_pipe_fogparams (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_fragment_pipe_fog (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_fragment_pipe_vdecl (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_fragment_pipe_vs (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_fragment_pipe_tex_transform (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_fragment_pipe_alpha_test_func (struct wined3d_context_gl *context_gl, const struct wined3d_state *state)
 
static void glsl_fragment_pipe_core_alpha_test (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static void glsl_fragment_pipe_alpha_test (struct wined3d_context_gl *context_gl, const struct wined3d_state *state)
 
static void glsl_fragment_pipe_shademode (struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
 
static BOOL glsl_fragment_pipe_alloc_context_data (struct wined3d_context *context)
 
static void glsl_fragment_pipe_free_context_data (struct wined3d_context *context)
 
static int glsl_blitter_args_compare (const void *key, const struct wine_rb_entry *entry)
 
static void glsl_free_blitter_program (struct wine_rb_entry *entry, void *ctx)
 
static void glsl_blitter_destroy (struct wined3d_blitter *blitter, struct wined3d_context *context)
 
static void glsl_blitter_generate_p8_shader (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const struct glsl_blitter_args *args, const char *output, const char *tex_type, const char *swizzle)
 
static void gen_packed_yuv_read (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const struct glsl_blitter_args *args, const char *tex_type)
 
static void gen_yv12_read (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const char *tex_type)
 
static void gen_nv12_read (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const char *tex_type)
 
static void glsl_blitter_generate_yuv_shader (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const struct glsl_blitter_args *args, const char *output, const char *tex_type, const char *swizzle)
 
static void glsl_blitter_generate_plain_shader (struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const struct glsl_blitter_args *args, const char *output, const char *tex_type, const char *swizzle)
 
static GLuint glsl_blitter_generate_program (struct wined3d_glsl_blitter *blitter, const struct wined3d_gl_info *gl_info, const struct glsl_blitter_args *args)
 
static void glsl_blitter_upload_palette (struct wined3d_glsl_blitter *blitter, struct wined3d_context_gl *context_gl, const struct wined3d_texture_gl *texture_gl)
 
static struct glsl_blitter_program * glsl_blitter_get_program (struct wined3d_glsl_blitter *blitter, struct wined3d_context_gl *context_gl, const struct wined3d_texture_gl *texture_gl, BOOL use_colour_key)
 
static BOOL glsl_blitter_supported (enum wined3d_blit_op blit_op, const struct wined3d_context *context, const struct wined3d_texture_gl *src_texture, DWORD src_location, const struct wined3d_texture_gl *dst_texture, DWORD dst_location)
 
static DWORD glsl_blitter_blit (struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key, enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format)
 
static void glsl_blitter_clear (struct wined3d_blitter *blitter, struct wined3d_device *device, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *color, float depth, unsigned int stencil)
 
struct wined3d_blitter * wined3d_glsl_blitter_create (struct wined3d_blitter **next, const struct wined3d_device *device)
 

Variables

struct {
   unsigned int   coord_size
 
   unsigned int   resinfo_size
 
   const char *   type_part
 
} resource_type_info []
 
struct {
   enum wined3d_data_type   data_type
 
   const char *   glsl_scalar_type
 
   const char *   glsl_vector_type
 
} component_type_info []
 
static const char *const shift_glsl_tab []
 
static const SHADER_HANDLER shader_glsl_instruction_handler_table [WINED3DSIH_TABLE_SIZE]
 
const struct wined3d_shader_backend_ops glsl_shader_backend
 
static const struct wined3d_state_entry_template glsl_vertex_pipe_vp_states []
 
const struct wined3d_vertex_pipe_ops glsl_vertex_pipe
 
static const struct wined3d_state_entry_template glsl_fragment_pipe_state_template []
 
const struct wined3d_fragment_pipe_ops glsl_fragment_pipe
 
static const struct wined3d_blitter_ops glsl_blitter_ops
 

Macro Definition Documentation

◆ WINED3D_GLSL_SAMPLE_GRAD

#define WINED3D_GLSL_SAMPLE_GRAD   0x04

Definition at line 44 of file glsl_shader.c.

◆ WINED3D_GLSL_SAMPLE_LOAD

#define WINED3D_GLSL_SAMPLE_LOAD   0x08

Definition at line 45 of file glsl_shader.c.

◆ WINED3D_GLSL_SAMPLE_LOD

#define WINED3D_GLSL_SAMPLE_LOD   0x02

Definition at line 43 of file glsl_shader.c.

◆ WINED3D_GLSL_SAMPLE_OFFSET

#define WINED3D_GLSL_SAMPLE_OFFSET   0x10

Definition at line 46 of file glsl_shader.c.

◆ WINED3D_GLSL_SAMPLE_PROJECTED

#define WINED3D_GLSL_SAMPLE_PROJECTED   0x01

Definition at line 42 of file glsl_shader.c.

◆ WINED3D_TO_STR

#define WINED3D_TO_STR (   u)    case u: return #u

Enumeration Type Documentation

◆ heap_node_op

Enumerator
HEAP_NODE_TRAVERSE_LEFT 
HEAP_NODE_TRAVERSE_RIGHT 
HEAP_NODE_POP 

Definition at line 104 of file glsl_shader.c.

105{
109};
@ HEAP_NODE_POP
Definition: glsl_shader.c:108
@ HEAP_NODE_TRAVERSE_RIGHT
Definition: glsl_shader.c:107
@ HEAP_NODE_TRAVERSE_LEFT
Definition: glsl_shader.c:106

Function Documentation

◆ add_glsl_program_entry()

static void add_glsl_program_entry ( struct shader_glsl_priv *  priv,
struct glsl_shader_prog_link *  entry 
)
static

Definition at line 7042 of file glsl_shader.c.

7043{
7044 struct glsl_program_key key;
7045
7046 key.vs_id = entry->vs.id;
7047 key.hs_id = entry->hs.id;
7048 key.ds_id = entry->ds.id;
7049 key.gs_id = entry->gs.id;
7050 key.ps_id = entry->ps.id;
7051 key.cs_id = entry->cs.id;
7052
7053 if (wine_rb_put(&priv->program_lookup, &key, &entry->program_lookup_entry) == -1)
7054 {
7055 ERR("Failed to insert program entry.\n");
7056 }
7057}
#define ERR(fmt,...)
Definition: precomp.h:57
uint32_t entry
Definition: isohybrid.c:63
#define wine_rb_put
Definition: rbtree.h:410
Definition: copy.c:22
struct wine_rb_tree program_lookup
Definition: glsl_shader.c:132

Referenced by set_glsl_shader_program(), and shader_glsl_compile_compute_shader().

◆ append_transform_feedback_skip_components()

static void append_transform_feedback_skip_components ( const char **  varyings,
unsigned int *  varying_count,
char **  strings,
unsigned int *  strings_length,
struct wined3d_string_buffer *  buffer,
unsigned int  component_count 
)
static

Definition at line 1028 of file glsl_shader.c.

1031{
1032 unsigned int j;
1033
1034 for (j = 0; j < component_count / 4; ++j)
1035 {
1036 string_buffer_sprintf(buffer, "gl_SkipComponents4");
1037 append_transform_feedback_varying(varyings, varying_count, strings, strings_length, buffer);
1038 }
1039 if (component_count % 4)
1040 {
1041 string_buffer_sprintf(buffer, "gl_SkipComponents%u", component_count % 4);
1042 append_transform_feedback_varying(varyings, varying_count, strings, strings_length, buffer);
1043 }
1044}
unsigned int component_count
void string_buffer_sprintf(struct wined3d_string_buffer *buffer, const char *format,...)
Definition: shader.c:515
GLsizei const GLchar *const * varyings
Definition: glext.h:6214
GLsizei const GLchar *const * strings
Definition: glext.h:7622
GLuint buffer
Definition: glext.h:5915
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static void append_transform_feedback_varying(const char **varyings, unsigned int *varying_count, char **strings, unsigned int *strings_length, struct wined3d_string_buffer *buffer)
Definition: glsl_shader.c:1009

Referenced by shader_glsl_generate_transform_feedback_varyings().

◆ append_transform_feedback_varying()

static void append_transform_feedback_varying ( const char **  varyings,
unsigned int *  varying_count,
char **  strings,
unsigned int *  strings_length,
struct wined3d_string_buffer *  buffer 
)
static

Definition at line 1009 of file glsl_shader.c.

1011{
1012 if (varyings && *strings)
1013 {
1014 char *ptr = *strings;
1015
1016 varyings[*varying_count] = ptr;
1017
1018 memcpy(ptr, buffer->buffer, buffer->content_size + 1);
1019 ptr += buffer->content_size + 1;
1020
1021 *strings = ptr;
1022 }
1023
1024 *strings_length += buffer->content_size + 1;
1025 ++(*varying_count);
1026}
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27

Referenced by append_transform_feedback_skip_components(), and shader_glsl_generate_transform_feedback_varyings().

◆ apply_clamped_constant()

static void apply_clamped_constant ( const struct wined3d_gl_info *  gl_info,
GLint  location,
const struct wined3d_vec4 *  data 
)
static

Definition at line 1299 of file glsl_shader.c.

1301{
1302 GLfloat clamped_constant[4];
1303
1304 if (location == -1) return;
1305
1306 clamped_constant[0] = data->x < -1.0f ? -1.0f : data->x > 1.0f ? 1.0f : data->x;
1307 clamped_constant[1] = data->y < -1.0f ? -1.0f : data->y > 1.0f ? 1.0f : data->y;
1308 clamped_constant[2] = data->z < -1.0f ? -1.0f : data->z > 1.0f ? 1.0f : data->z;
1309 clamped_constant[3] = data->w < -1.0f ? -1.0f : data->w > 1.0f ? 1.0f : data->w;
1310
1311 GL_EXTCALL(glUniform4fv(location, 1, clamped_constant));
1312}
float GLfloat
Definition: gl.h:161
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define GL_EXTCALL(f)
Definition: wined3d_gl.h:360

Referenced by walk_constant_heap_clamped().

◆ constant_free()

static void constant_free ( struct constant_heap *  heap)
static

Definition at line 11210 of file glsl_shader.c.

11211{
11212 free(heap->entries);
11213}
#define free
Definition: debug_ros.c:5
Definition: heap.c:86

Referenced by shader_glsl_alloc(), and shader_glsl_free().

◆ constant_heap_init()

static BOOL constant_heap_init ( struct constant_heap *  heap,
unsigned int  constant_count 
)
static

Definition at line 11187 of file glsl_shader.c.

11188{
11189 SIZE_T size = (constant_count + 1) * sizeof(*heap->entries)
11190 + constant_count * sizeof(*heap->contained)
11191 + constant_count * sizeof(*heap->positions);
11192 void *mem;
11193
11194 if (!(mem = malloc(size)))
11195 {
11196 ERR("Failed to allocate memory\n");
11197 return FALSE;
11198 }
11199
11200 heap->entries = mem;
11201 heap->entries[1].version = 0;
11202 heap->contained = (BOOL *)(heap->entries + constant_count + 1);
11203 memset(heap->contained, 0, constant_count * sizeof(*heap->contained));
11204 heap->positions = (unsigned int *)(heap->contained + constant_count);
11205 heap->size = 1;
11206
11207 return TRUE;
11208}
#define malloc
Definition: debug_ros.c:4
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizeiptr size
Definition: glext.h:5919
UINT constant_count
Definition: shader.c:5886
#define memset(x, y, z)
Definition: compat.h:39
Definition: mem.c:349
ULONG_PTR SIZE_T
Definition: typedefs.h:80

Referenced by shader_glsl_alloc().

◆ create_combined_resource_sampler_bindings()

static struct vkd3d_shader_combined_resource_sampler * create_combined_resource_sampler_bindings ( const struct wined3d_context_gl *  context_gl,
const struct wined3d_shader *  shader,
unsigned int *  count 
)
static

Definition at line 661 of file glsl_shader.c.

663{
665 unsigned int bind_idx, shader_sampler_count, base, i;
667 enum vkd3d_shader_visibility visibility;
668 const unsigned int *tex_unit_map;
669
670 tex_unit_map = wined3d_context_gl_get_tex_unit_mapping(context_gl,
671 &shader->reg_maps.shader_version, &base, count);
672
673 shader_sampler_count = shader->reg_maps.sampler_map.count;
674 if (shader_sampler_count > *count)
675 {
676 FIXME("Shader %p needs %u samplers, but only %u are supported.\n",
677 shader, shader_sampler_count, *count);
678 return NULL;
679 }
680 *count = min(shader_sampler_count, *count);
681
682 if (!(bindings = calloc(*count, sizeof(*bindings))))
683 return NULL;
684
685 visibility = vkd3d_shader_visibility_from_wined3d(shader->reg_maps.shader_version.type);
686 for (i = 0; i < *count; ++i)
687 {
688 entry = &shader->reg_maps.sampler_map.entries[i];
689 bind_idx = base + entry->bind_idx;
690 if (tex_unit_map)
691 bind_idx = tex_unit_map[bind_idx];
692
693 bindings[i].resource_space = 0;
694 bindings[i].resource_index = entry->resource_idx;
695 bindings[i].sampler_space = 0;
696 bindings[i].sampler_index = entry->sampler_idx;
697 bindings[i].shader_visibility = visibility;
699 bindings[i].binding.set = 0;
700 bindings[i].binding.binding = bind_idx;
701 bindings[i].binding.count = 1;
702 }
703
704 return bindings;
705}
#define FIXME(fmt,...)
Definition: precomp.h:53
const unsigned int * wined3d_context_gl_get_tex_unit_mapping(const struct wined3d_context_gl *context_gl, const struct wined3d_shader_version *shader_version, unsigned int *base, unsigned int *count)
Definition: context_gl.c:2350
#define NULL
Definition: types.h:112
enum vkd3d_shader_visibility vkd3d_shader_visibility_from_wined3d(enum wined3d_shader_type shader_type)
Definition: shader.c:309
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint shader
Definition: glext.h:6030
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define min(a, b)
Definition: monoChain.cc:55
#define calloc
Definition: rosglue.h:14
struct vkd3d_shader_descriptor_binding binding
Definition: vkd3d_shader.h:994
enum vkd3d_shader_visibility shader_visibility
Definition: vkd3d_shader.h:989
unsigned int bind_idx
vkd3d_shader_visibility
Definition: vkd3d_shader.h:383
@ VKD3D_SHADER_BINDING_FLAG_IMAGE
Definition: vkd3d_shader.h:469

Referenced by shader_glsl_generate_vkd3d_shader().

◆ create_resource_bindings()

static struct vkd3d_shader_resource_binding * create_resource_bindings ( const struct wined3d_gl_info *  gl_info,
enum wined3d_shader_type  shader_type,
unsigned int *  count 
)
static

Definition at line 634 of file glsl_shader.c.

636{
637 struct vkd3d_shader_resource_binding *bindings;
638 enum vkd3d_shader_visibility visibility;
639 unsigned int base, i;
640
642 if (!(bindings = calloc(*count, sizeof(*bindings))))
643 return NULL;
644
646 for (i = 0; i < *count; ++i)
647 {
649 bindings[i].register_space = 0;
650 bindings[i].register_index = i;
651 bindings[i].shader_visibility = visibility;
653 bindings[i].binding.set = 0;
654 bindings[i].binding.binding = base + i;
655 bindings[i].binding.count = 1;
656 }
657
658 return bindings;
659}
void wined3d_gl_limits_get_uniform_block_range(const struct wined3d_gl_limits *gl_limits, enum wined3d_shader_type shader_type, unsigned int *base, unsigned int *count)
Definition: utils.c:6694
struct vkd3d_shader_descriptor_binding binding
Definition: vkd3d_shader.h:961
enum vkd3d_shader_descriptor_type type
Definition: vkd3d_shader.h:940
enum vkd3d_shader_visibility shader_visibility
Definition: vkd3d_shader.h:956
struct wined3d_gl_limits limits
Definition: wined3d_gl.h:344
@ VKD3D_SHADER_DESCRIPTOR_TYPE_CBV
Definition: vkd3d_shader.h:435
@ VKD3D_SHADER_BINDING_FLAG_BUFFER
Definition: vkd3d_shader.h:468

Referenced by shader_glsl_generate_vkd3d_shader().

◆ debug_gl_shader_type()

static const char * debug_gl_shader_type ( GLenum  type)
static

Definition at line 353 of file glsl_shader.c.

354{
355 switch (type)
356 {
357#define WINED3D_TO_STR(u) case u: return #u
364#undef WINED3D_TO_STR
365 default:
366 return wine_dbg_sprintf("UNKNOWN(%#x)", type);
367 }
368}
const char * wine_dbg_sprintf(const char *format,...)
Definition: compat.c:296
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define GL_FRAGMENT_SHADER
Definition: glext.h:419
#define GL_GEOMETRY_SHADER
Definition: glext.h:820
#define GL_TESS_CONTROL_SHADER
Definition: glext.h:2126
#define GL_TESS_EVALUATION_SHADER
Definition: glext.h:2125
#define GL_VERTEX_SHADER
Definition: glext.h:420
#define WINED3D_TO_STR(u)
#define GL_COMPUTE_SHADER
Definition: wgl.h:691

Referenced by shader_glsl_dump_program_source().

◆ delete_glsl_program_entry()

static void delete_glsl_program_entry ( struct shader_glsl_priv *  priv,
const struct wined3d_gl_info *  gl_info,
struct glsl_shader_prog_link *  entry 
)
static

Definition at line 7069 of file glsl_shader.c.

7071{
7072 wine_rb_remove(&priv->program_lookup, &entry->program_lookup_entry);
7073
7074 GL_EXTCALL(glDeleteProgram(entry->id));
7075 if (entry->vs.id)
7076 list_remove(&entry->vs.shader_entry);
7077 if (entry->hs.id)
7078 list_remove(&entry->hs.shader_entry);
7079 if (entry->ds.id)
7080 list_remove(&entry->ds.shader_entry);
7081 if (entry->gs.id)
7082 list_remove(&entry->gs.shader_entry);
7083 if (entry->ps.id)
7084 list_remove(&entry->ps.shader_entry);
7085 if (entry->cs.id)
7086 list_remove(&entry->cs.shader_entry);
7087 free(entry);
7088}
static void list_remove(struct list_entry *entry)
Definition: list.h:90
#define wine_rb_remove
Definition: rbtree.h:411

Referenced by shader_glsl_destroy(), shader_glsl_free_ffp_fragment_shader(), and shader_glsl_free_ffp_vertex_shader().

◆ find_glsl_compute_shader()

static GLuint find_glsl_compute_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
struct wined3d_shader *  shader 
)
static

Definition at line 10352 of file glsl_shader.c.

10354{
10355 struct glsl_shader_private *shader_data;
10356
10357 if (!shader->backend_data)
10358 {
10359 WARN("Failed to find GLSL program for compute shader %p.\n", shader);
10360 if (FAILED(shader_glsl_compile_compute_shader(priv, context_gl, shader)))
10361 {
10362 ERR("Failed to compile compute shader %p.\n", shader);
10363 return 0;
10364 }
10365 }
10366 shader_data = shader->backend_data;
10367 return shader_data->gl_shaders.cs[0].id;
10368}
#define WARN(fmt,...)
Definition: precomp.h:61
static HRESULT shader_glsl_compile_compute_shader(struct shader_glsl_priv *priv, const struct wined3d_context_gl *context_gl, struct wined3d_shader *shader)
#define FAILED(hr)
Definition: intsafe.h:51
struct glsl_cs_compiled_shader * cs
Definition: glsl_shader.c:326
union glsl_shader_private::@338 gl_shaders

Referenced by set_glsl_compute_shader_program().

◆ find_glsl_domain_shader()

static GLuint find_glsl_domain_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
struct wined3d_shader *  shader,
const struct ds_compile_args *  args 
)
static

Definition at line 8875 of file glsl_shader.c.

8877{
8878 struct glsl_ds_compiled_shader *gl_shaders, *new_array;
8879 struct glsl_shader_private *shader_data;
8880 unsigned int i, new_size;
8881 GLuint ret;
8882
8883 if (!shader->backend_data)
8884 {
8885 if (!(shader->backend_data = calloc(1, sizeof(*shader_data))))
8886 {
8887 ERR("Failed to allocate backend data.\n");
8888 return 0;
8889 }
8890 }
8891 shader_data = shader->backend_data;
8892 gl_shaders = shader_data->gl_shaders.ds;
8893
8894 for (i = 0; i < shader_data->num_gl_shaders; ++i)
8895 {
8896 if (!memcmp(&gl_shaders[i].args, args, sizeof(*args)))
8897 return gl_shaders[i].id;
8898 }
8899
8900 TRACE("No matching GL shader found for shader %p, compiling a new shader.\n", shader);
8901
8902 if (shader_data->num_gl_shaders)
8903 {
8904 new_size = shader_data->shader_array_size + 1;
8905 new_array = realloc(shader_data->gl_shaders.ds, new_size * sizeof(*new_array));
8906 }
8907 else
8908 {
8909 new_array = malloc(sizeof(*new_array));
8910 new_size = 1;
8911 }
8912
8913 if (!new_array)
8914 {
8915 ERR("Failed to allocate GL shaders array.\n");
8916 return 0;
8917 }
8918 shader_data->gl_shaders.ds = new_array;
8919 shader_data->shader_array_size = new_size;
8920 gl_shaders = new_array;
8921
8923 ret = shader_glsl_generate_domain_shader(context_gl, priv, shader, args);
8924 gl_shaders[shader_data->num_gl_shaders].args = *args;
8925 gl_shaders[shader_data->num_gl_shaders++].id = ret;
8926
8927 return ret;
8928}
#define realloc
Definition: debug_ros.c:6
void string_buffer_clear(struct wined3d_string_buffer *buffer)
Definition: shader.c:411
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
return ret
Definition: mutex.c:147
size_t const new_size
Definition: expand.cpp:66
unsigned int GLuint
Definition: gl.h:159
static GLuint shader_glsl_generate_domain_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader, const struct ds_compile_args *args)
Definition: glsl_shader.c:8414
#define args
Definition: format.c:66
#define TRACE(s)
Definition: solgame.cpp:4
Definition: match.c:390
unsigned int num_gl_shaders
Definition: glsl_shader.c:328
struct glsl_ds_compiled_shader * ds
Definition: glsl_shader.c:323
unsigned int shader_array_size
Definition: glsl_shader.c:328
struct wined3d_string_buffer shader_buffer
Definition: glsl_shader.c:130

Referenced by set_glsl_shader_program().

◆ find_glsl_fragment_shader()

static GLuint find_glsl_fragment_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
struct wined3d_shader *  shader,
const struct ps_compile_args *  args 
)
static

Definition at line 8685 of file glsl_shader.c.

8687{
8688 struct glsl_ps_compiled_shader *gl_shaders, *new_array;
8689 struct glsl_shader_private *shader_data;
8690 UINT i;
8692 GLuint ret;
8693
8694 if (!shader->backend_data)
8695 {
8696 if (!(shader->backend_data = calloc(1, sizeof(*shader_data))))
8697 {
8698 ERR("Failed to allocate backend data.\n");
8699 return 0;
8700 }
8701 }
8702 shader_data = shader->backend_data;
8703 gl_shaders = shader_data->gl_shaders.ps;
8704
8705 /* Usually we have very few GL shaders for each d3d shader(just 1 or maybe 2),
8706 * so a linear search is more performant than a hashmap or a binary search
8707 * (cache coherency etc)
8708 */
8709 for (i = 0; i < shader_data->num_gl_shaders; ++i)
8710 {
8711 if (!memcmp(&gl_shaders[i].args, args, sizeof(*args)))
8712 return gl_shaders[i].id;
8713 }
8714
8715 TRACE("No matching GL shader found for shader %p, compiling a new shader.\n", shader);
8716 if (shader_data->shader_array_size == shader_data->num_gl_shaders)
8717 {
8718 if (shader_data->num_gl_shaders)
8719 {
8720 new_size = shader_data->shader_array_size + max(1, shader_data->shader_array_size / 2);
8721 new_array = realloc(shader_data->gl_shaders.ps, new_size * sizeof(*gl_shaders));
8722 }
8723 else
8724 {
8725 new_array = malloc(sizeof(*gl_shaders));
8726 new_size = 1;
8727 }
8728
8729 if(!new_array) {
8730 ERR("Out of memory\n");
8731 return 0;
8732 }
8733 shader_data->gl_shaders.ps = new_array;
8734 shader_data->shader_array_size = new_size;
8735 gl_shaders = new_array;
8736 }
8737
8738 gl_shaders[shader_data->num_gl_shaders].args = *args;
8739
8742 gl_shaders[shader_data->num_gl_shaders++].id = ret;
8743
8744 return ret;
8745}
unsigned long DWORD
Definition: ntddk_ex.h:95
static GLuint shader_glsl_generate_fragment_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader, const struct ps_compile_args *args)
Definition: glsl_shader.c:7837
unsigned int UINT
Definition: sysinfo.c:13
struct glsl_ps_compiled_shader * ps
Definition: glsl_shader.c:325
#define max(a, b)
Definition: svc.c:63

Referenced by set_glsl_shader_program().

◆ find_glsl_geometry_shader()

static GLuint find_glsl_geometry_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
struct wined3d_shader *  shader,
const struct gs_compile_args *  args 
)
static

Definition at line 8930 of file glsl_shader.c.

8932{
8933 struct glsl_gs_compiled_shader *gl_shaders, *new_array;
8934 struct glsl_shader_private *shader_data;
8935 unsigned int i, new_size;
8936 GLuint ret;
8937
8938 if (!shader->backend_data)
8939 {
8940 if (!(shader->backend_data = calloc(1, sizeof(*shader_data))))
8941 {
8942 ERR("Failed to allocate backend data.\n");
8943 return 0;
8944 }
8945 }
8946 shader_data = shader->backend_data;
8947 gl_shaders = shader_data->gl_shaders.gs;
8948
8949 for (i = 0; i < shader_data->num_gl_shaders; ++i)
8950 {
8951 if (!memcmp(&gl_shaders[i].args, args, sizeof(*args)))
8952 return gl_shaders[i].id;
8953 }
8954
8955 TRACE("No matching GL shader found for shader %p, compiling a new shader.\n", shader);
8956
8957 if (shader_data->num_gl_shaders)
8958 {
8959 new_size = shader_data->shader_array_size + 1;
8960 new_array = realloc(shader_data->gl_shaders.gs, new_size * sizeof(*new_array));
8961 }
8962 else
8963 {
8964 new_array = malloc(sizeof(*new_array));
8965 new_size = 1;
8966 }
8967
8968 if (!new_array)
8969 {
8970 ERR("Failed to allocate GL shaders array.\n");
8971 return 0;
8972 }
8973 shader_data->gl_shaders.gs = new_array;
8974 shader_data->shader_array_size = new_size;
8975 gl_shaders = new_array;
8976
8979 gl_shaders[shader_data->num_gl_shaders].args = *args;
8980 gl_shaders[shader_data->num_gl_shaders++].id = ret;
8981
8982 return ret;
8983}
static GLuint shader_glsl_generate_geometry_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader, const struct gs_compile_args *args)
Definition: glsl_shader.c:8506
struct glsl_gs_compiled_shader * gs
Definition: glsl_shader.c:324

Referenced by set_glsl_shader_program().

◆ find_glsl_hull_shader()

static GLuint find_glsl_hull_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
struct wined3d_shader *  shader 
)
static

Definition at line 8830 of file glsl_shader.c.

8832{
8833 struct glsl_hs_compiled_shader *gl_shaders, *new_array;
8834 struct glsl_shader_private *shader_data;
8835 unsigned int new_size;
8836 GLuint ret;
8837
8838 if (!shader->backend_data)
8839 {
8840 if (!(shader->backend_data = calloc(1, sizeof(*shader_data))))
8841 {
8842 ERR("Failed to allocate backend data.\n");
8843 return 0;
8844 }
8845 }
8846 shader_data = shader->backend_data;
8847 gl_shaders = shader_data->gl_shaders.hs;
8848
8849 if (shader_data->num_gl_shaders > 0)
8850 {
8851 assert(shader_data->num_gl_shaders == 1);
8852 return gl_shaders[0].id;
8853 }
8854
8855 TRACE("No matching GL shader found for shader %p, compiling a new shader.\n", shader);
8856
8857 assert(!shader_data->gl_shaders.hs);
8858 new_size = 1;
8859 if (!(new_array = malloc(sizeof(*new_array))))
8860 {
8861 ERR("Failed to allocate GL shaders array.\n");
8862 return 0;
8863 }
8864 shader_data->gl_shaders.hs = new_array;
8865 shader_data->shader_array_size = new_size;
8866 gl_shaders = new_array;
8867
8869 ret = shader_glsl_generate_hull_shader(context_gl, priv, shader);
8870 gl_shaders[shader_data->num_gl_shaders++].id = ret;
8871
8872 return ret;
8873}
#define assert(_expr)
Definition: assert.h:32
static GLuint shader_glsl_generate_hull_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader)
Definition: glsl_shader.c:8314
struct glsl_hs_compiled_shader * hs
Definition: glsl_shader.c:322

Referenced by set_glsl_shader_program().

◆ find_glsl_vertex_shader()

static GLuint find_glsl_vertex_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
struct wined3d_shader *  shader,
const struct vs_compile_args *  args 
)
static

Definition at line 8767 of file glsl_shader.c.

8769{
8770 struct glsl_vs_compiled_shader *gl_shaders, *new_array;
8771 uint32_t use_map = context_gl->c.stream_info.use_map;
8772 struct glsl_shader_private *shader_data;
8773 unsigned int i, new_size;
8774 GLuint ret;
8775
8776 if (!shader->backend_data)
8777 {
8778 if (!(shader->backend_data = calloc(1, sizeof(*shader_data))))
8779 {
8780 ERR("Failed to allocate backend data.\n");
8781 return 0;
8782 }
8783 }
8784 shader_data = shader->backend_data;
8785 gl_shaders = shader_data->gl_shaders.vs;
8786
8787 /* Usually we have very few GL shaders for each d3d shader(just 1 or maybe 2),
8788 * so a linear search is more performant than a hashmap or a binary search
8789 * (cache coherency etc)
8790 */
8791 for (i = 0; i < shader_data->num_gl_shaders; ++i)
8792 {
8793 if (vs_args_equal(&gl_shaders[i].args, args, use_map))
8794 return gl_shaders[i].id;
8795 }
8796
8797 TRACE("No matching GL shader found for shader %p, compiling a new shader.\n", shader);
8798
8799 if (shader_data->shader_array_size == shader_data->num_gl_shaders)
8800 {
8801 if (shader_data->num_gl_shaders)
8802 {
8803 new_size = shader_data->shader_array_size + max(1, shader_data->shader_array_size / 2);
8804 new_array = realloc(shader_data->gl_shaders.vs, new_size * sizeof(*gl_shaders));
8805 }
8806 else
8807 {
8808 new_array = malloc(sizeof(*gl_shaders));
8809 new_size = 1;
8810 }
8811
8812 if(!new_array) {
8813 ERR("Out of memory\n");
8814 return 0;
8815 }
8816 shader_data->gl_shaders.vs = new_array;
8817 shader_data->shader_array_size = new_size;
8818 gl_shaders = new_array;
8819 }
8820
8821 gl_shaders[shader_data->num_gl_shaders].args = *args;
8822
8824 ret = shader_glsl_generate_vertex_shader(context_gl, priv, shader, args);
8825 gl_shaders[shader_data->num_gl_shaders++].id = ret;
8826
8827 return ret;
8828}
UINT32 uint32_t
Definition: types.h:75
static GLuint shader_glsl_generate_vertex_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader, const struct vs_compile_args *args)
Definition: glsl_shader.c:8167
static BOOL vs_args_equal(const struct vs_compile_args *stored, const struct vs_compile_args *new, const DWORD use_map)
Definition: glsl_shader.c:8747
struct glsl_vs_compiled_shader * vs
Definition: glsl_shader.c:321
struct wined3d_context c
Definition: wined3d_gl.h:601

Referenced by set_glsl_shader_program().

◆ gen_nv12_read()

static void gen_nv12_read ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info,
const char *  tex_type 
)
static

Definition at line 12606 of file glsl_shader.c.

12608{
12609 char component = gl_info->supported[WINED3D_GL_LEGACY_CONTEXT] ? 'w' : 'x';
12610 const char *tex = needs_legacy_glsl_syntax(gl_info) ? tex_type : "";
12611
12612 /* NV12 surfaces contain a WxH sized luminance plane, followed by a
12613 * (W/2)x(H/2) sized plane where each component is an UV pair. So the
12614 * effective bitdepth is 12 bits per pixel. If the whole texture is
12615 * interpreted as luminance data it looks approximately like this:
12616 *
12617 * +----------------------------------+----
12618 * | |
12619 * | |
12620 * | |
12621 * | |
12622 * | | 2
12623 * | LUMINANCE | -
12624 * | | 3
12625 * | |
12626 * | |
12627 * | |
12628 * | |
12629 * +----------------------------------+----
12630 * |UVUVUVUVUVUVUVUVUVUVUVUVUVUVUVUVUV|
12631 * |UVUVUVUVUVUVUVUVUVUVUVUVUVUVUVUVUV|
12632 * | | 1
12633 * | | -
12634 * | | 3
12635 * | |
12636 * | |
12637 * +----------------------------------+---- */
12638
12639 /* First sample the chroma values. */
12640 shader_addline(buffer, " texcoord.xy = out_texcoord.xy;\n");
12641 /* We only have half the number of chroma pixels. */
12642 shader_addline(buffer, " texcoord.x *= 0.5;\n");
12643 shader_addline(buffer, " texcoord.y = (texcoord.y + 2.0) / 3.0;\n");
12644
12645 /* We must not allow filtering horizontally, this would mix U and V.
12646 * Vertical filtering is ok. However, bear in mind that the pixel center
12647 * is at 0.5, so add 0.5. */
12648
12649 /* Convert to non-normalised coordinates so we can find the individual
12650 * pixel. */
12651 shader_addline(buffer, " texcoord.x = floor(texcoord.x * size.x);\n");
12652 /* Multiply by 2 since chroma components are stored in UV pixel pairs, add
12653 * 0.5 to hit the center of the pixel. Then convert back to normalised
12654 * coordinates. */
12655 shader_addline(buffer, " texcoord.x = (texcoord.x * 2.0 + 0.5) / size.x;\n");
12656 /* Clamp, keep the half pixel origin in mind. */
12657 shader_addline(buffer, " texcoord.y = max(texcoord.y, 2.0 / 3.0 + 0.5 / size.y);\n");
12658
12659 shader_addline(buffer, " chroma.y = texture%s(sampler, texcoord.xy).%c;\n", tex, component);
12660 /* Add 1.0 / size.x to sample the adjacent texel. */
12661 shader_addline(buffer, " texcoord.x += 1.0 / size.x;\n");
12662 shader_addline(buffer, " chroma.x = texture%s(sampler, texcoord.xy).%c;\n", tex, component);
12663
12664 /* Sample the luminance value. It is in the top 2/3rd of the texture, so
12665 * scale the y coordinate. Clamp the y coordinate to prevent the chroma
12666 * values from bleeding into the sampled luminance values due to
12667 * filtering. */
12668 shader_addline(buffer, " texcoord.xy = out_texcoord.xy;\n");
12669 /* Multiply the y coordinate by 2/3 and clamp it. */
12670 shader_addline(buffer, " texcoord.y = min(texcoord.y * 2.0 / 3.0, 2.0 / 3.0 - 0.5 / size.y);\n");
12671 shader_addline(buffer, " luminance = texture%s(sampler, texcoord.xy).%c;\n", tex, component);
12672}
int shader_addline(struct wined3d_string_buffer *buffer, const char *format,...)
Definition: shader.c:467
static BOOL needs_legacy_glsl_syntax(const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:2087
BOOL supported[WINED3D_GL_EXT_COUNT]
Definition: wined3d_gl.h:347
@ WINED3D_GL_LEGACY_CONTEXT
Definition: wined3d_gl.h:232

Referenced by glsl_blitter_generate_yuv_shader().

◆ gen_packed_yuv_read()

static void gen_packed_yuv_read ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info,
const struct glsl_blitter_args *  args,
const char *  tex_type 
)
static

Definition at line 12425 of file glsl_shader.c.

12428{
12430 char chroma, luminance;
12431 const char *tex;
12432
12433 /* The YUY2 and UYVY formats contain two pixels packed into a 32 bit
12434 * macropixel, giving effectively 16 bits per pixel. The color consists of
12435 * a luminance(Y) and two chroma(U and V) values. Each macropixel has two
12436 * luminance values, one for each single pixel it contains, and one U and
12437 * one V value shared between both pixels.
12438 *
12439 * The data is loaded into an A8L8 texture. With YUY2, the luminance
12440 * component contains the luminance and alpha the chroma. With UYVY it is
12441 * vice versa. Thus take the format into account when generating the read
12442 * swizzles
12443 *
12444 * Reading the Y value is straightforward - just sample the texture. The
12445 * hardware takes care of filtering in the horizontal and vertical
12446 * direction.
12447 *
12448 * Reading the U and V values is harder. We have to avoid filtering
12449 * horizontally, because that would mix the U and V values of one pixel or
12450 * two adjacent pixels. Thus floor the texture coordinate and add 0.5 to
12451 * get an unfiltered read, regardless of the filtering setting. Vertical
12452 * filtering works automatically though - the U and V values of two rows
12453 * are mixed nicely.
12454 *
12455 * Apart of avoiding filtering issues, the code has to know which value it
12456 * just read, and where it can find the other one. To determine this, it
12457 * checks if it sampled an even or odd pixel, and shifts the 2nd read
12458 * accordingly.
12459 *
12460 * Handling horizontal filtering of U and V values requires reading a 2nd
12461 * pair of pixels, extracting U and V and mixing them. This is not
12462 * implemented yet.
12463 *
12464 * An alternative implementation idea is to load the texture as A8R8G8B8
12465 * texture, with width / 2. This way one read gives all 3 values, finding
12466 * U and V is easy in an unfiltered situation. Finding the luminance on
12467 * the other hand requires finding out if it is an odd or even pixel. The
12468 * real drawback of this approach is filtering. This would have to be
12469 * emulated completely in the shader, reading up two 2 packed pixels in up
12470 * to 2 rows and interpolating both horizontally and vertically. Beyond
12471 * that it would require adjustments to the texture handling code to deal
12472 * with the width scaling. */
12473
12475 {
12476 chroma = 'x';
12477 luminance = gl_info->supported[WINED3D_GL_LEGACY_CONTEXT] ? 'w' : 'y';
12478 }
12479 else
12480 {
12481 chroma = gl_info->supported[WINED3D_GL_LEGACY_CONTEXT] ? 'w' : 'y';
12482 luminance = 'x';
12483 }
12484
12485 tex = needs_legacy_glsl_syntax(gl_info) ? tex_type : "";
12486
12487 /* First we have to read the chroma values. This means we need at least
12488 * two pixels (no filtering), or 4 pixels (with filtering). To get the
12489 * unmodified chroma, we have to rid ourselves of the filtering when we
12490 * sample the texture. */
12491 shader_addline(buffer, " texcoord.xy = out_texcoord.xy;\n");
12492 /* We must not allow filtering between pixel x and x+1, this would mix U
12493 * and V. Vertical filtering is ok. However, bear in mind that the pixel
12494 * center is at 0.5, so add 0.5. */
12495 shader_addline(buffer, " texcoord.x = (floor(texcoord.x * size.x) + 0.5) / size.x;\n");
12496 shader_addline(buffer, " luminance = texture%s(sampler, texcoord.xy).%c;\n", tex, chroma);
12497
12498 /* Multiply the x coordinate by 0.5 and get the fraction. This gives 0.25
12499 * and 0.75 for the even and odd pixels respectively. */
12500 /* Put the value into either of the chroma values. */
12501 shader_addline(buffer, " bool even = fract(texcoord.x * size.x * 0.5) < 0.5;\n");
12502 shader_addline(buffer, " if (even)\n");
12503 shader_addline(buffer, " chroma.y = luminance;\n");
12504 shader_addline(buffer, " else\n");
12505 shader_addline(buffer, " chroma.x = luminance;\n");
12506
12507 /* Sample pixel 2. If we read an even pixel, sample the pixel right to the
12508 * current one. Otherwise, sample the left pixel. */
12509 shader_addline(buffer, " texcoord.x += even ? 1.0 / size.x : -1.0 / size.x;\n");
12510 shader_addline(buffer, " luminance = texture%s(sampler, texcoord.xy).%c;\n", tex, chroma);
12511
12512 /* Put the value into the other chroma. */
12513 shader_addline(buffer, " if (even)\n");
12514 shader_addline(buffer, " chroma.x = luminance;\n");
12515 shader_addline(buffer, " else\n");
12516 shader_addline(buffer, " chroma.y = luminance;\n");
12517
12518 /* TODO: If filtering is enabled, sample a 2nd pair of pixels left or right of
12519 * the current one and lerp the two U and V values. */
12520
12521 /* This gives the correctly filtered luminance value. */
12522 shader_addline(buffer, " luminance = texture%s(sampler, out_texcoord.xy).%c;\n", tex, luminance);
12523}
static enum complex_fixup get_complex_fixup(struct color_fixup_desc fixup)
complex_fixup
@ COMPLEX_FIXUP_UYVY

Referenced by glsl_blitter_generate_yuv_shader().

◆ gen_yv12_read()

static void gen_yv12_read ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info,
const char *  tex_type 
)
static

Definition at line 12525 of file glsl_shader.c.

12527{
12528 char component = gl_info->supported[WINED3D_GL_LEGACY_CONTEXT] ? 'w' : 'x';
12529 const char *tex = needs_legacy_glsl_syntax(gl_info) ? tex_type : "";
12530
12531 /* YV12 surfaces contain a WxH sized luminance plane, followed by a
12532 * (W/2)x(H/2) V and a (W/2)x(H/2) U plane, each with 8 bit per pixel. So
12533 * the effective bitdepth is 12 bits per pixel. Since the U and V planes
12534 * have only half the pitch of the luminance plane, the packing into the
12535 * gl texture is a bit unfortunate. If the whole texture is interpreted as
12536 * luminance data it looks approximately like this:
12537 *
12538 * +----------------------------------+----
12539 * | |
12540 * | |
12541 * | |
12542 * | |
12543 * | | 2
12544 * | LUMINANCE | -
12545 * | | 3
12546 * | |
12547 * | |
12548 * | |
12549 * | |
12550 * +----------------+-----------------+----
12551 * | | |
12552 * | V even rows | V odd rows |
12553 * | | | 1
12554 * +----------------+------------------ -
12555 * | | | 3
12556 * | U even rows | U odd rows |
12557 * | | |
12558 * +----------------+-----------------+----
12559 * | | |
12560 * | 0.5 | 0.5 |
12561 *
12562 * So it appears as if there are 4 chroma images, but in fact the odd rows
12563 * in the chroma images are in the same row as the even ones. So it is
12564 * kinda tricky to read. */
12565
12566 /* First sample the chroma values. */
12567 shader_addline(buffer, " texcoord.xy = out_texcoord.xy;\n");
12568 /* The chroma planes have only half the width. */
12569 shader_addline(buffer, " texcoord.x *= 0.5;\n");
12570
12571 /* The first value is between 2/3 and 5/6 of the texture's height, so
12572 * scale+bias the coordinate. Also read the right side of the image when
12573 * reading odd lines.
12574 *
12575 * Don't forget to clamp the y values in into the range, otherwise we'll
12576 * get filtering bleeding. */
12577
12578 /* Read odd lines from the right side (add 0.5 to the x coordinate). Keep
12579 * in mind that each line of the chroma plane corresponds to 2 lines of the
12580 * resulting image. */
12581 shader_addline(buffer, " if (fract(texcoord.y * size.y * 0.25) >= 0.5)\n");
12582 shader_addline(buffer, " texcoord.x += 0.5;\n");
12583
12584 /* Clamp, keep the half pixel origin in mind. */
12585 shader_addline(buffer, " texcoord.y = clamp(2.0 / 3.0 + texcoord.y / 6.0, "
12586 "2.0 / 3.0 + 0.5 / size.y, 5.0 / 6.0 - 0.5 / size.y);\n");
12587
12588 shader_addline(buffer, " chroma.x = texture%s(sampler, texcoord.xy).%c;\n", tex, component);
12589
12590 /* The other chroma value is 1/6th of the texture lower, from 5/6th to
12591 * 6/6th No need to clamp because we're just reusing the already clamped
12592 * value from above. */
12593 shader_addline(buffer, " texcoord.y += 1.0 / 6.0;\n");
12594 shader_addline(buffer, " chroma.y = texture%s(sampler, texcoord.xy).%c;\n", tex, component);
12595
12596 /* Sample the luminance value. It is in the top 2/3rd of the texture, so
12597 * scale the y coordinate. Clamp the y coordinate to prevent the chroma
12598 * values from bleeding into the sampled luminance values due to
12599 * filtering. */
12600 shader_addline(buffer, " texcoord.xy = out_texcoord.xy;\n");
12601 /* Multiply the y coordinate by 2/3 and clamp it. */
12602 shader_addline(buffer, " texcoord.y = min(texcoord.y * 2.0 / 3.0, 2.0 / 3.0 - 0.5 / size.y);\n");
12603 shader_addline(buffer, " luminance = texture%s(sampler, texcoord.xy).%c;\n", tex, component);
12604}

Referenced by glsl_blitter_generate_yuv_shader().

◆ get_attribute_keyword()

static const char * get_attribute_keyword ( const struct wined3d_gl_info *  gl_info)
static

◆ get_fragment_output()

static const char * get_fragment_output ( const struct wined3d_gl_info *  gl_info)
static

◆ get_glsl_program_entry()

static struct glsl_shader_prog_link * get_glsl_program_entry ( const struct shader_glsl_priv *  priv,
const struct glsl_program_key *  key 
)
static

Definition at line 7059 of file glsl_shader.c.

7061{
7062 struct wine_rb_entry *entry;
7063
7065 return entry ? WINE_RB_ENTRY_VALUE(entry, struct glsl_shader_prog_link, program_lookup_entry) : NULL;
7066}
#define wine_rb_entry
Definition: rbtree.h:404
#define WINE_RB_ENTRY_VALUE
Definition: rbtree.h:414
#define wine_rb_get
Definition: rbtree.h:409

Referenced by set_glsl_compute_shader_program(), and set_glsl_shader_program().

◆ get_projection_matrix()

static void get_projection_matrix ( const struct wined3d_context *  context,
const struct wined3d_ffp_vs_constants *  constants,
const struct wined3d_state *  state,
struct wined3d_matrix *  mat 
)
static

Definition at line 1480 of file glsl_shader.c.

1482{
1483 const struct wined3d_d3d_info *d3d_info = context->d3d_info;
1484 bool clip_control, flip;
1485 float center_offset;
1486
1487 /* There are a couple of additional things we have to take into account
1488 * here besides the projection transformation itself:
1489 * - We need to flip along the y-axis in case of offscreen rendering.
1490 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
1491 * - <= D3D9 coordinates refer to pixel centers while GL coordinates
1492 * refer to pixel corners. D3D10 fixed this particular oddity.
1493 * - D3D has a top-left filling convention while GL does not specify
1494 * a particular behavior, other than that that the GL implementation
1495 * needs to be consistent.
1496 *
1497 * In order to handle the pixel center, we translate by 0.5 / VPw and
1498 * 0.5 / VPh. We test the filling convention during adapter init and
1499 * add a small offset to correct it if necessary. See
1500 * wined3d_caps_gl_ctx_test_filling_convention() for more details on how
1501 * we test GL and considerations regarding the added offset value.
1502 *
1503 * If we have GL_ARB_clip_control we take care of all this through
1504 * viewport properties and don't have to translate geometry. */
1505
1506 /* Projection matrices are <= d3d9, which all have integer pixel centers. */
1508 ERR("Did not expect to enter this codepath without WINED3D_PIXEL_CENTER_INTEGER.\n");
1509
1510 clip_control = d3d_info->clip_control;
1511 flip = !clip_control;
1512 if (!clip_control)
1513 center_offset = 1.0f + d3d_info->filling_convention_offset;
1514 else
1515 center_offset = 0.0f;
1516
1517 if (context->stream_info.position_transformed)
1518 {
1519 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
1520 float x = state->viewports[0].x;
1521 float y = state->viewports[0].y;
1522 float w = state->viewports[0].width;
1523 float h = state->viewports[0].height;
1524 float x_scale = 2.0f / w;
1525 float x_offset = (center_offset - (2.0f * x) - w) / w;
1526 float y_scale = flip ? 2.0f / h : 2.0f / -h;
1527 float y_offset = flip
1528 ? (center_offset - (2.0f * y) - h) / h
1529 : (center_offset - (2.0f * y) - h) / -h;
1530 bool zenable = state->fb.depth_stencil ?
1531 (state->depth_stencil_state ? state->depth_stencil_state->desc.depth : true) : false;
1532 float z_scale = zenable ? clip_control ? 1.0f : 2.0f : 0.0f;
1533 float z_offset = zenable ? clip_control ? 0.0f : -1.0f : 0.0f;
1534 const struct wined3d_matrix projection =
1535 {
1536 x_scale, 0.0f, 0.0f, 0.0f,
1537 0.0f, y_scale, 0.0f, 0.0f,
1538 0.0f, 0.0f, z_scale, 0.0f,
1539 x_offset, y_offset, z_offset, 1.0f,
1540 };
1541
1542 *mat = projection;
1543 }
1544 else
1545 {
1546 float y_scale = flip ? -1.0f : 1.0f;
1547 float x_offset = center_offset / state->viewports[0].width;
1548 float y_offset = flip
1549 ? center_offset / state->viewports[0].height
1550 : -center_offset / state->viewports[0].height;
1551 float z_scale = clip_control ? 1.0f : 2.0f;
1552 float z_offset = clip_control ? 0.0f : -1.0f;
1553 const struct wined3d_matrix projection =
1554 {
1555 1.0f, 0.0f, 0.0f, 0.0f,
1556 0.0f, y_scale, 0.0f, 0.0f,
1557 0.0f, 0.0f, z_scale, 0.0f,
1558 x_offset, y_offset, z_offset, 1.0f,
1559 };
1560
1561 multiply_matrix(mat, &projection, &constants->projection_matrix);
1562 }
1563}
static int state
Definition: maze.c:121
void multiply_matrix(struct wined3d_matrix *dst, const struct wined3d_matrix *src1, const struct wined3d_matrix *src2)
Definition: utils.c:1153
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
static const MAT2 mat
Definition: font.c:51
constants
Definition: resource.c:30
Definition: http.c:7252
uint32_t wined3d_creation_flags
float filling_convention_offset
#define WINED3D_PIXEL_CENTER_INTEGER
Definition: wined3d.h:1328

Referenced by shader_glsl_load_constants().

◆ glsl_blitter_args_compare()

static int glsl_blitter_args_compare ( const void *  key,
const struct wine_rb_entry *  entry 
)
static

Definition at line 12362 of file glsl_shader.c.

12363{
12364 const struct glsl_blitter_args *a = key;
12365 const struct glsl_blitter_args *b = &WINE_RB_ENTRY_VALUE(entry, const struct glsl_blitter_program, entry)->args;
12366
12367 return memcmp(a, b, sizeof(*a));
12368}
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by wined3d_glsl_blitter_create().

◆ glsl_blitter_blit()

static DWORD glsl_blitter_blit ( struct wined3d_blitter *  blitter,
enum wined3d_blit_op  op,
struct wined3d_context *  context,
struct wined3d_texture *  src_texture,
unsigned int  src_sub_resource_idx,
DWORD  src_location,
const RECT *  src_rect,
struct wined3d_texture *  dst_texture,
unsigned int  dst_sub_resource_idx,
DWORD  dst_location,
const RECT *  dst_rect,
const struct wined3d_color_key *  colour_key,
enum wined3d_texture_filter_type  filter,
const struct wined3d_format *  resolve_format 
)
static

Definition at line 13031 of file glsl_shader.c.

13037{
13038 struct wined3d_texture_gl *src_texture_gl = wined3d_texture_gl(src_texture);
13039 struct wined3d_texture_gl *dst_texture_gl = wined3d_texture_gl(dst_texture);
13040 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
13041 struct wined3d_device *device = dst_texture->resource.device;
13042 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
13043 struct wined3d_texture *staging_texture = NULL;
13044 struct wined3d_glsl_blitter *glsl_blitter;
13045 struct wined3d_color_key alpha_test_key;
13047 struct wined3d_blitter *next;
13048 unsigned int src_level;
13050 RECT d;
13051
13052 TRACE("blitter %p, op %#x, context %p, src_texture %p, src_sub_resource_idx %u, src_location %s, "
13053 "src_rect %s, dst_texture %p, dst_sub_resource_idx %u, dst_location %s, dst_rect %s, "
13054 "colour_key %p, filter %s, resolve format %p.\n",
13055 blitter, op, context, src_texture, src_sub_resource_idx, wined3d_debug_location(src_location),
13056 wine_dbgstr_rect(src_rect), dst_texture, dst_sub_resource_idx, wined3d_debug_location(dst_location),
13057 wine_dbgstr_rect(dst_rect), colour_key, debug_d3dtexturefiltertype(filter), resolve_format);
13058
13059 if (!glsl_blitter_supported(op, context, src_texture_gl, src_location, dst_texture_gl, dst_location))
13060 {
13061 if (!(next = blitter->next))
13062 {
13063 ERR("No blitter to handle blit op %#x.\n", op);
13064 return dst_location;
13065 }
13066
13067 TRACE("Forwarding to blitter %p.\n", next);
13068 return next->ops->blitter_blit(next, op, context, src_texture, src_sub_resource_idx, src_location,
13069 src_rect, dst_texture, dst_sub_resource_idx, dst_location, dst_rect, colour_key, filter,
13070 resolve_format);
13071 }
13072
13073 glsl_blitter = CONTAINING_RECORD(blitter, struct wined3d_glsl_blitter, blitter);
13074
13075 if (!(src_texture->resource.access & WINED3D_RESOURCE_ACCESS_GPU))
13076 {
13078 struct wined3d_box upload_box;
13079 HRESULT hr;
13080
13081 TRACE("Source texture is not GPU accessible, creating a staging texture.\n");
13082
13083 src_level = src_sub_resource_idx % src_texture->level_count;
13084 desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
13085 desc.format = src_texture->resource.format->id;
13086 desc.multisample_type = src_texture->resource.multisample_type;
13087 desc.multisample_quality = src_texture->resource.multisample_quality;
13088 desc.usage = WINED3DUSAGE_CS;
13089 desc.bind_flags = 0;
13091 desc.width = wined3d_texture_get_level_width(src_texture, src_level);
13092 desc.height = wined3d_texture_get_level_height(src_texture, src_level);
13093 desc.depth = 1;
13094 desc.size = 0;
13095
13096 if (FAILED(hr = wined3d_texture_create(device, &desc, 1, 1, 0,
13097 NULL, NULL, &wined3d_null_parent_ops, &staging_texture)))
13098 {
13099 ERR("Failed to create staging texture, hr %#lx.\n", hr);
13100 return dst_location;
13101 }
13102
13103 wined3d_box_set(&upload_box, 0, 0, desc.width, desc.height, 0, desc.depth);
13104 wined3d_texture_upload_from_texture(staging_texture, 0, 0, 0, 0,
13105 src_texture, src_sub_resource_idx, &upload_box);
13106
13107 src_texture = staging_texture;
13108 src_texture_gl = wined3d_texture_gl(src_texture);
13109 src_sub_resource_idx = 0;
13110 }
13111 else
13112 {
13113 wined3d_texture_load(src_texture, context, FALSE);
13114 }
13115
13116 if (wined3d_texture_is_full_rect(dst_texture, dst_sub_resource_idx % dst_texture->level_count, dst_rect))
13117 wined3d_texture_prepare_location(dst_texture, dst_sub_resource_idx, context, dst_location);
13118 else
13119 wined3d_texture_load_location(dst_texture, dst_sub_resource_idx, context, dst_location);
13120
13121 context_gl_apply_texture_draw_state(context_gl, dst_texture, dst_sub_resource_idx, dst_location);
13123
13124 if (dst_location == WINED3D_LOCATION_DRAWABLE)
13125 {
13126 d = *dst_rect;
13127 wined3d_texture_translate_drawable_coords(dst_texture, context_gl->window, &d);
13128 dst_rect = &d;
13129 }
13130
13132 {
13133 const struct wined3d_format *f = src_texture->resource.format;
13134
13135 alpha_test_key.color_space_low_value = 0;
13136 alpha_test_key.color_space_high_value = ~(wined3d_mask_from_size(f->alpha_size) << f->alpha_offset);
13137 colour_key = &alpha_test_key;
13138 }
13140 {
13141 colour_key = NULL;
13142 }
13143
13144 if (!(program = glsl_blitter_get_program(glsl_blitter, context_gl, src_texture_gl, !!colour_key)))
13145 {
13146 ERR("Failed to get blitter program.\n");
13147 return dst_location;
13148 }
13149 GL_EXTCALL(glUseProgram(program->id));
13150 switch (get_complex_fixup(program->args.fixup))
13151 {
13152 case COMPLEX_FIXUP_P8:
13153 glsl_blitter_upload_palette(glsl_blitter, context_gl, src_texture_gl);
13154 break;
13155
13156 case COMPLEX_FIXUP_YUY2:
13157 case COMPLEX_FIXUP_UYVY:
13158 case COMPLEX_FIXUP_YV12:
13159 case COMPLEX_FIXUP_NV12:
13160 case COMPLEX_FIXUP_YUV:
13161 src_level = src_sub_resource_idx % src_texture->level_count;
13162 location = GL_EXTCALL(glGetUniformLocation(program->id, "size"));
13163 GL_EXTCALL(glUniform2f(location, wined3d_texture_get_level_width(src_texture, src_level),
13164 wined3d_texture_get_level_height(src_texture, src_level)));
13165 break;
13166
13167 default:
13168 break;
13169 }
13170 if (colour_key)
13171 {
13172 struct wined3d_color float_key[2];
13173
13174 wined3d_format_get_float_color_key(src_texture->resource.format, colour_key, float_key);
13175 location = GL_EXTCALL(glGetUniformLocation(program->id, "colour_key.low"));
13176 GL_EXTCALL(glUniform4fv(location, 1, &float_key[0].r));
13177 location = GL_EXTCALL(glGetUniformLocation(program->id, "colour_key.high"));
13178 GL_EXTCALL(glUniform4fv(location, 1, &float_key[1].r));
13179 }
13180 wined3d_context_gl_draw_shaded_quad(context_gl, src_texture_gl, src_sub_resource_idx, src_rect, dst_rect, filter);
13181 GL_EXTCALL(glUseProgram(0));
13182
13183 if (dst_texture->swapchain && (dst_texture->swapchain->front_buffer == dst_texture))
13184 gl_info->gl_ops.gl.p_glFlush();
13185
13186 if (staging_texture)
13187 wined3d_texture_decref(staging_texture);
13188
13189 return dst_location;
13190}
static const char * wine_dbgstr_rect(const RECT *prc)
Definition: atltest.h:160
void wined3d_context_gl_apply_blit_state(struct wined3d_context_gl *context_gl, const struct wined3d_device *device)
Definition: context_gl.c:3156
void wined3d_context_gl_draw_shaded_quad(struct wined3d_context_gl *context_gl, struct wined3d_texture_gl *texture_gl, unsigned int sub_resource_idx, const RECT *src_rect, const RECT *dst_rect, enum wined3d_texture_filter_type filter)
Definition: context_gl.c:5125
void context_gl_apply_texture_draw_state(struct wined3d_context_gl *context_gl, struct wined3d_texture *texture, unsigned int sub_resource_idx, unsigned int location)
Definition: context_gl.c:3384
HRESULT hr
Definition: delayimp.cpp:582
UINT op
Definition: effect.c:235
HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct wined3d_resource_desc *desc, UINT layer_count, UINT level_count, uint32_t flags, const struct wined3d_sub_resource_data *data, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture)
Definition: texture.c:4158
void wined3d_texture_translate_drawable_coords(const struct wined3d_texture *texture, HWND window, RECT *rect)
Definition: texture.c:91
ULONG CDECL wined3d_texture_decref(struct wined3d_texture *texture)
Definition: texture.c:1606
void wined3d_texture_upload_from_texture(struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, unsigned int dst_x, unsigned int dst_y, unsigned int dst_z, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, const struct wined3d_box *src_box)
Definition: texture.c:4335
BOOL wined3d_texture_prepare_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, unsigned int location)
Definition: texture.c:2116
BOOL wined3d_texture_load_location(struct wined3d_texture *texture, unsigned int sub_resource_idx, struct wined3d_context *context, uint32_t location)
Definition: texture.c:770
void wined3d_texture_load(struct wined3d_texture *texture, struct wined3d_context *context, BOOL srgb)
Definition: texture.c:1657
const char * wined3d_debug_location(uint32_t location)
Definition: utils.c:6588
const char * debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type)
Definition: utils.c:5194
void wined3d_format_get_float_color_key(const struct wined3d_format *format, const struct wined3d_color_key *key, struct wined3d_color *float_colors)
Definition: utils.c:5997
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
int GLint
Definition: gl.h:156
GLuint program
Definition: glext.h:6723
GLfloat f
Definition: glext.h:7540
static void glsl_blitter_upload_palette(struct wined3d_glsl_blitter *blitter, struct wined3d_context_gl *context_gl, const struct wined3d_texture_gl *texture_gl)
static struct glsl_blitter_program * glsl_blitter_get_program(struct wined3d_glsl_blitter *blitter, struct wined3d_context_gl *context_gl, const struct wined3d_texture_gl *texture_gl, BOOL use_colour_key)
static BOOL glsl_blitter_supported(enum wined3d_blit_op blit_op, const struct wined3d_context *context, const struct wined3d_texture_gl *src_texture, DWORD src_location, const struct wined3d_texture_gl *dst_texture, DWORD dst_location)
#define d
Definition: ke_i.h:81
#define location(file, line)
Definition: kmtest.h:18
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683
static unsigned __int64 next
Definition: rand_nt.c:6
Definition: dcommon.idl:28
Definition: devices.h:37
Definition: filter.c:165
struct wined3d_blitter * next
const struct wined3d_gl_info * gl_info
Definition: wined3d_gl.h:603
struct opengl_funcs gl_ops
Definition: wined3d_gl.h:353
struct wined3d_swapchain * swapchain
struct wined3d_resource resource
unsigned int level_count
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
const struct wined3d_parent_ops wined3d_null_parent_ops
Definition: directx.c:3472
#define WINED3D_RESOURCE_ACCESS_GPU
Definition: wined3d.h:51
@ WINED3D_RTYPE_TEXTURE_2D
Definition: wined3d.h:720
static void wined3d_box_set(struct wined3d_box *box, unsigned int left, unsigned int top, unsigned int right, unsigned int bottom, unsigned int front, unsigned int back)
Definition: wined3d.h:3006
#define WINED3DUSAGE_CS
Definition: wined3d.h:933
static unsigned int wined3d_texture_get_level_height(const struct wined3d_texture *texture, unsigned int level)
static unsigned int wined3d_texture_get_level_width(const struct wined3d_texture *texture, unsigned int level)
static bool wined3d_texture_is_full_rect(const struct wined3d_texture *texture, unsigned int level, const RECT *r)
static uint32_t wined3d_mask_from_size(unsigned int size)
#define WINED3D_LOCATION_DRAWABLE
@ COMPLEX_FIXUP_P8
@ COMPLEX_FIXUP_YUY2
@ COMPLEX_FIXUP_NV12
@ COMPLEX_FIXUP_YV12
@ COMPLEX_FIXUP_YUV
@ WINED3D_BLIT_OP_COLOR_BLIT_CKEY
@ WINED3D_BLIT_OP_COLOR_BLIT_ALPHATEST

◆ glsl_blitter_clear()

static void glsl_blitter_clear ( struct wined3d_blitter *  blitter,
struct wined3d_device *  device,
unsigned int  rt_count,
const struct wined3d_fb_state *  fb,
unsigned int  rect_count,
const RECT *  clear_rects,
const RECT *  draw_rect,
uint32_t  flags,
const struct wined3d_color *  color,
float  depth,
unsigned int  stencil 
)
static

Definition at line 13192 of file glsl_shader.c.

13195{
13196 struct wined3d_blitter *next;
13197
13198 if ((next = blitter->next))
13199 next->ops->blitter_clear(next, device, rt_count, fb, rect_count,
13200 clear_rects, draw_rect, flags, color, depth, stencil);
13201}
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLuint color
Definition: glext.h:6243
GLbitfield flags
Definition: glext.h:7161
GLint GLfloat GLint stencil
Definition: glext.h:6260

◆ glsl_blitter_destroy()

static void glsl_blitter_destroy ( struct wined3d_blitter *  blitter,
struct wined3d_context *  context 
)
static

Definition at line 12384 of file glsl_shader.c.

12385{
12386 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
12387 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
12388 struct wined3d_glsl_blitter *glsl_blitter;
12389 struct wined3d_blitter *next;
12390
12391 if ((next = blitter->next))
12392 next->ops->blitter_destroy(next, context);
12393
12394 glsl_blitter = CONTAINING_RECORD(blitter, struct wined3d_glsl_blitter, blitter);
12395
12396 if (glsl_blitter->palette_texture)
12397 gl_info->gl_ops.gl.p_glDeleteTextures(1, &glsl_blitter->palette_texture);
12398
12399 wine_rb_destroy(&glsl_blitter->programs, glsl_free_blitter_program, context_gl);
12401
12402 free(glsl_blitter);
12403}
void string_buffer_list_cleanup(struct wined3d_string_buffer_list *list)
Definition: shader.c:544
static void glsl_free_blitter_program(struct wine_rb_entry *entry, void *ctx)
#define wine_rb_destroy
Definition: rbtree.h:408
struct wine_rb_tree programs
struct wined3d_string_buffer_list string_buffers

◆ glsl_blitter_generate_p8_shader()

static void glsl_blitter_generate_p8_shader ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info,
const struct glsl_blitter_args *  args,
const char *  output,
const char *  tex_type,
const char *  swizzle 
)
static

Definition at line 12405 of file glsl_shader.c.

12408{
12409 shader_addline(buffer, "uniform sampler1D sampler_palette;\n");
12410 shader_addline(buffer, "\nvoid main()\n{\n");
12411 /* The alpha-component contains the palette index. */
12412 shader_addline(buffer, " float index = texture%s(sampler, out_texcoord.%s).%c;\n",
12413 needs_legacy_glsl_syntax(gl_info) ? tex_type : "", swizzle,
12414 gl_info->supported[WINED3D_GL_LEGACY_CONTEXT] ? 'w' : 'x');
12415 /* Scale the index by 255/256 and add a bias of 0.5 in order to sample in
12416 * the middle. */
12417 shader_addline(buffer, " index = (index * 255.0 + 0.5) / 256.0;\n");
12418 shader_addline(buffer, " %s = texture%s(sampler_palette, index);\n",
12419 output, needs_legacy_glsl_syntax(gl_info) ? "1D" : "");
12420 if (args->use_colour_key)
12421 shader_glsl_generate_colour_key_test(buffer, output, "colour_key.low", "colour_key.high");
12422 shader_addline(buffer, "}\n");
12423}
GLuint GLenum swizzle
Definition: glext.h:9511
static void shader_glsl_generate_colour_key_test(struct wined3d_string_buffer *buffer, const char *colour, const char *colour_key_low, const char *colour_key_high)
Definition: glsl_shader.c:7705

Referenced by glsl_blitter_generate_program().

◆ glsl_blitter_generate_plain_shader()

static void glsl_blitter_generate_plain_shader ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info,
const struct glsl_blitter_args *  args,
const char *  output,
const char *  tex_type,
const char *  swizzle 
)
static

Definition at line 12732 of file glsl_shader.c.

12735{
12736 shader_addline(buffer, "\nvoid main()\n{\n");
12737 shader_addline(buffer, " %s = texture%s(sampler, out_texcoord.%s);\n",
12738 output, needs_legacy_glsl_syntax(gl_info) ? tex_type : "", swizzle);
12740 if (args->use_colour_key)
12741 shader_glsl_generate_colour_key_test(buffer, output, "colour_key.low", "colour_key.high");
12742 shader_addline(buffer, "}\n");
12743}
static void shader_glsl_color_correction_ext(struct wined3d_string_buffer *buffer, const char *reg_name, DWORD mask, struct color_fixup_desc fixup)
Definition: glsl_shader.c:3731
#define WINED3DSP_WRITEMASK_ALL

Referenced by glsl_blitter_generate_program().

◆ glsl_blitter_generate_program()

static GLuint glsl_blitter_generate_program ( struct wined3d_glsl_blitter *  blitter,
const struct wined3d_gl_info *  gl_info,
const struct glsl_blitter_args *  args 
)
static

Definition at line 12746 of file glsl_shader.c.

12748{
12749 static const struct
12750 {
12751 GLenum texture_target;
12752 const char texture_type[7];
12753 const char texcoord_swizzle[4];
12754 }
12755 texture_data[] =
12756 {
12757 {GL_TEXTURE_2D, "2D", "xy"},
12758 {GL_TEXTURE_CUBE_MAP, "Cube", "xyz"},
12759 };
12760 static const char vshader_main[] =
12761 "\n"
12762 "void main()\n"
12763 "{\n"
12764 " gl_Position = vec4(pos, 0.0, 1.0);\n"
12765 " out_texcoord = texcoord;\n"
12766 "}\n";
12768 struct wined3d_string_buffer *buffer, *output;
12769 GLuint program, vshader_id, fshader_id;
12770 const char *tex_type = NULL, *swizzle = NULL, *ptr;
12771 unsigned int i;
12772 GLint loc;
12773
12774 for (i = 0; i < ARRAY_SIZE(texture_data); ++i)
12775 {
12776 if (args->texture_type == texture_data[i].texture_target)
12777 {
12778 tex_type = texture_data[i].texture_type;
12779 swizzle = texture_data[i].texcoord_swizzle;
12780 break;
12781 }
12782 }
12783 if (i == ARRAY_SIZE(texture_data))
12784 {
12785 FIXME("Unsupported texture type %#x.\n", args->texture_type);
12786 return 0;
12787 }
12788
12789 program = GL_EXTCALL(glCreateProgram());
12790
12791 vshader_id = GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER));
12792
12795 shader_addline(buffer, "%s vec2 pos;\n", get_attribute_keyword(gl_info));
12796 shader_addline(buffer, "%s vec3 texcoord;\n", get_attribute_keyword(gl_info));
12797 declare_out_varying(gl_info, buffer, FALSE, "vec3 out_texcoord;\n");
12798 shader_addline(buffer, vshader_main);
12799
12800 ptr = buffer->buffer;
12801 GL_EXTCALL(glShaderSource(vshader_id, 1, &ptr, NULL));
12802 GL_EXTCALL(glAttachShader(program, vshader_id));
12803 GL_EXTCALL(glDeleteShader(vshader_id));
12804
12805 fshader_id = GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER));
12806
12809 shader_addline(buffer, "uniform sampler%s sampler;\n", tex_type);
12810 if (args->use_colour_key)
12811 {
12812 shader_addline(buffer, "uniform struct\n{\n");
12813 shader_addline(buffer, " vec4 low, high;\n");
12814 shader_addline(buffer, "} colour_key;\n");
12815 }
12816 declare_in_varying(gl_info, buffer, FALSE, "vec3 out_texcoord;\n");
12817 /* TODO: Declare the out variable with the correct type (and put it in the
12818 * blitter args). */
12819 if (!use_legacy_fragment_output(gl_info))
12820 shader_addline(buffer, "out vec4 ps_out[1];\n");
12821
12822 output = string_buffer_get(&blitter->string_buffers);
12823 string_buffer_sprintf(output, "%s[0]", get_fragment_output(gl_info));
12824
12825 switch (complex_fixup)
12826 {
12827 case COMPLEX_FIXUP_P8:
12828 glsl_blitter_generate_p8_shader(buffer, gl_info, args, output->buffer, tex_type, swizzle);
12829 break;
12830 case COMPLEX_FIXUP_YUY2:
12831 case COMPLEX_FIXUP_UYVY:
12832 case COMPLEX_FIXUP_YV12:
12833 case COMPLEX_FIXUP_NV12:
12834 case COMPLEX_FIXUP_YUV:
12835 glsl_blitter_generate_yuv_shader(buffer, gl_info, args, output->buffer, tex_type, swizzle);
12836 break;
12837 case COMPLEX_FIXUP_NONE:
12838 glsl_blitter_generate_plain_shader(buffer, gl_info, args, output->buffer, tex_type, swizzle);
12839 }
12840
12841 string_buffer_release(&blitter->string_buffers, output);
12842
12843 ptr = buffer->buffer;
12844 GL_EXTCALL(glShaderSource(fshader_id, 1, &ptr, NULL));
12846 GL_EXTCALL(glAttachShader(program, fshader_id));
12847 GL_EXTCALL(glDeleteShader(fshader_id));
12848
12849 GL_EXTCALL(glBindAttribLocation(program, 0, "pos"));
12850 GL_EXTCALL(glBindAttribLocation(program, 1, "texcoord"));
12851
12852 if (!use_legacy_fragment_output(gl_info))
12853 GL_EXTCALL(glBindFragDataLocation(program, 0, "ps_out"));
12854
12855 GL_EXTCALL(glCompileShader(vshader_id));
12856 print_glsl_info_log(gl_info, vshader_id, FALSE);
12857 GL_EXTCALL(glCompileShader(fshader_id));
12858 print_glsl_info_log(gl_info, fshader_id, FALSE);
12859 GL_EXTCALL(glLinkProgram(program));
12861
12862 GL_EXTCALL(glUseProgram(program));
12863 loc = GL_EXTCALL(glGetUniformLocation(program, "sampler"));
12864 GL_EXTCALL(glUniform1i(loc, 0));
12866 {
12867 loc = GL_EXTCALL(glGetUniformLocation(program, "sampler_palette"));
12868 GL_EXTCALL(glUniform1i(loc, 1));
12869 }
12870
12871 return program;
12872}
#define ARRAY_SIZE(A)
Definition: main.h:20
struct wined3d_string_buffer * string_buffer_get(struct wined3d_string_buffer_list *list)
Definition: shader.c:484
void string_buffer_release(struct wined3d_string_buffer_list *list, struct wined3d_string_buffer *buffer)
Definition: shader.c:532
#define GL_TEXTURE_CUBE_MAP
Definition: gl.h:1788
unsigned int GLenum
Definition: gl.h:150
#define GL_TEXTURE_2D
Definition: gl.h:645
static void glsl_blitter_generate_yuv_shader(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const struct glsl_blitter_args *args, const char *output, const char *tex_type, const char *swizzle)
static void glsl_blitter_generate_p8_shader(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const struct glsl_blitter_args *args, const char *output, const char *tex_type, const char *swizzle)
void shader_glsl_validate_link(const struct wined3d_gl_info *gl_info, GLuint program)
Definition: glsl_shader.c:617
static void shader_glsl_add_version_declaration(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:410
static const char * get_attribute_keyword(const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:2103
static const char * get_fragment_output(const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:2262
static void glsl_blitter_generate_plain_shader(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const struct glsl_blitter_args *args, const char *output, const char *tex_type, const char *swizzle)
void print_glsl_info_log(const struct wined3d_gl_info *gl_info, GLuint id, BOOL program)
Definition: glsl_shader.c:485
@ COMPLEX_FIXUP_NONE

Referenced by glsl_blitter_get_program().

◆ glsl_blitter_generate_yuv_shader()

static void glsl_blitter_generate_yuv_shader ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info,
const struct glsl_blitter_args *  args,
const char *  output,
const char *  tex_type,
const char *  swizzle 
)
static

Definition at line 12674 of file glsl_shader.c.

12677{
12679
12680 shader_addline(buffer, "const vec4 yuv_coef = vec4(1.403, -0.344, -0.714, 1.770);\n");
12681 shader_addline(buffer, "float luminance;\n");
12682 shader_addline(buffer, "vec2 texcoord;\n");
12683 shader_addline(buffer, "vec2 chroma;\n");
12684 shader_addline(buffer, "uniform vec2 size;\n");
12685
12686 shader_addline(buffer, "\nvoid main()\n{\n");
12687
12688 switch (complex_fixup)
12689 {
12690 case COMPLEX_FIXUP_UYVY:
12691 case COMPLEX_FIXUP_YUY2:
12692 gen_packed_yuv_read(buffer, gl_info, args, tex_type);
12693 break;
12694
12695 case COMPLEX_FIXUP_YV12:
12696 gen_yv12_read(buffer, gl_info, tex_type);
12697 break;
12698
12699 case COMPLEX_FIXUP_NV12:
12700 gen_nv12_read(buffer, gl_info, tex_type);
12701 break;
12702
12703 case COMPLEX_FIXUP_YUV:
12704 /* With APPLE_rgb_422, things are much simpler. The only thing we
12705 * have to do here is Y'CbCr to RGB conversion. */
12706 shader_addline(buffer, " vec3 yuv = vec3(texture%s(sampler, out_texcoord.xy));\n",
12707 needs_legacy_glsl_syntax(gl_info) ? tex_type : "");
12708 shader_addline(buffer, " luminance = yuv.y;\n");
12709 shader_addline(buffer, " chroma = yuv.xz;\n");
12710 break;
12711
12712 default:
12713 FIXME("Unsupported fixup %#x.\n", complex_fixup);
12715 return;
12716 }
12717
12718 /* Calculate the final result. Formula is taken from
12719 * http://www.fourcc.org/fccyvrgb.php. Note that the chroma
12720 * ranges from -0.5 to 0.5. */
12721 shader_addline(buffer, "\n chroma.xy -= 0.5;\n");
12722
12723 shader_addline(buffer, " %s.x = luminance + chroma.x * yuv_coef.x;\n", output);
12724 shader_addline(buffer, " %s.y = luminance + chroma.y * yuv_coef.y + chroma.x * yuv_coef.z;\n", output);
12725 shader_addline(buffer, " %s.z = luminance + chroma.y * yuv_coef.w;\n", output);
12726 if (args->use_colour_key)
12727 shader_glsl_generate_colour_key_test(buffer, output, "colour_key.low", "colour_key.high");
12728
12729 shader_addline(buffer, "}\n");
12730}
void string_buffer_free(struct wined3d_string_buffer *buffer)
Definition: shader.c:430
static void gen_packed_yuv_read(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const struct glsl_blitter_args *args, const char *tex_type)
static void gen_nv12_read(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const char *tex_type)
static void gen_yv12_read(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const char *tex_type)

Referenced by glsl_blitter_generate_program().

◆ glsl_blitter_get_program()

static struct glsl_blitter_program * glsl_blitter_get_program ( struct wined3d_glsl_blitter *  blitter,
struct wined3d_context_gl *  context_gl,
const struct wined3d_texture_gl *  texture_gl,
BOOL  use_colour_key 
)
static

Definition at line 12913 of file glsl_shader.c.

12915{
12916 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
12918 struct glsl_blitter_args args;
12919 struct wine_rb_entry *entry;
12920
12921 memset(&args, 0, sizeof(args));
12922 args.texture_type = texture_gl->target;
12923 args.fixup = texture_gl->t.resource.format->color_fixup;
12924 args.use_colour_key = use_colour_key;
12925
12926 if ((entry = wine_rb_get(&blitter->programs, &args)))
12928
12929 if (!(program = malloc(sizeof(*program))))
12930 {
12931 ERR("Failed to allocate blitter program memory.\n");
12932 return NULL;
12933 }
12934
12935 program->args = args;
12936 if (!(program->id = glsl_blitter_generate_program(blitter, gl_info, &args)))
12937 {
12938 WARN("Failed to generate blitter program.\n");
12939 free(program);
12940 return NULL;
12941 }
12942
12943 if (wine_rb_put(&blitter->programs, &program->args, &program->entry) == -1)
12944 {
12945 ERR("Failed to store blitter program.\n");
12946 GL_EXTCALL(glDeleteProgram(program->id));
12947 free(program);
12948 return NULL;
12949 }
12950
12951 return program;
12952}
static GLuint glsl_blitter_generate_program(struct wined3d_glsl_blitter *blitter, const struct wined3d_gl_info *gl_info, const struct glsl_blitter_args *args)
struct wined3d_texture t
Definition: wined3d_gl.h:941

Referenced by glsl_blitter_blit().

◆ glsl_blitter_supported()

static BOOL glsl_blitter_supported ( enum wined3d_blit_op  blit_op,
const struct wined3d_context *  context,
const struct wined3d_texture_gl *  src_texture,
DWORD  src_location,
const struct wined3d_texture_gl *  dst_texture,
DWORD  dst_location 
)
static

Definition at line 12954 of file glsl_shader.c.

12957{
12958 const struct wined3d_resource *src_resource = &src_texture->t.resource;
12959 const struct wined3d_resource *dst_resource = &dst_texture->t.resource;
12960 const struct wined3d_format *src_format = src_resource->format;
12961 const struct wined3d_format *dst_format = dst_resource->format;
12962 bool src_ds, dst_ds;
12964
12965 if (blit_op == WINED3D_BLIT_OP_RAW_BLIT && dst_format->id == src_format->id)
12966 {
12967 src_ds = src_format->depth_size || src_format->stencil_size;
12968 dst_ds = dst_format->depth_size || dst_format->stencil_size;
12969 /* We could in principle support raw depth/stencil <-> colour blits as
12970 * well in some cases, but note that typeless formats like e.g.
12971 * R16_TYPELESS may use a normalised GL format for depth/stencil
12972 * resources, and a floating-point format for colour resources, */
12973 if (src_ds && dst_ds)
12975 else if (!src_ds && !dst_ds)
12977 }
12978
12981 {
12982 TRACE("Unsupported blit_op %#x.\n", blit_op);
12983 return FALSE;
12984 }
12985
12986 if (src_resource->type != WINED3D_RTYPE_TEXTURE_2D)
12987 return FALSE;
12988
12989 if (src_texture->target == GL_TEXTURE_2D_MULTISAMPLE
12990 || src_texture->target == GL_TEXTURE_2D_MULTISAMPLE_ARRAY)
12991 {
12992 TRACE("Multi-sample source textures not supported.\n");
12993 return FALSE;
12994 }
12995
12996 if (!(dst_resource->access & WINED3D_RESOURCE_ACCESS_GPU))
12997 {
12998 TRACE("Destination resource does not have GPU access.\n");
12999 return FALSE;
13000 }
13001
13002 /* We don't necessarily want to blit from resources without
13003 * WINED3D_RESOURCE_ACCESS_GPU, but that may be the only way to decompress
13004 * compressed textures. */
13007 if (!decompress && !(src_resource->access & WINED3D_RESOURCE_ACCESS_GPU))
13008 {
13009 TRACE("Source resource does not have GPU access.\n");
13010 return FALSE;
13011 }
13012
13013 if (!is_identity_fixup(dst_format->color_fixup)
13014 && (dst_format->id != src_format->id || dst_location != WINED3D_LOCATION_DRAWABLE))
13015 {
13016 TRACE("Destination fixups are not supported.\n");
13017 return FALSE;
13018 }
13019
13021 || (dst_resource->bind_flags & WINED3D_BIND_RENDER_TARGET)))
13022 {
13023 TRACE("Destination texture is not FBO attachable.\n");
13024 return FALSE;
13025 }
13026
13027 TRACE("Returning supported.\n");
13028 return TRUE;
13029}
#define GL_TEXTURE_2D_MULTISAMPLE_ARRAY
Definition: glext.h:1941
#define GL_TEXTURE_2D_MULTISAMPLE
Definition: glext.h:1939
static const char * dst_format
Definition: dib.c:1339
unsigned int attrs
enum wined3d_format_id id
void(* decompress)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch, unsigned int dst_row_pitch, unsigned dst_slice_pitch, unsigned int width, unsigned int height, unsigned int depth)
enum wined3d_resource_type type
unsigned int access
const struct wined3d_format * format
unsigned int bind_flags
#define WINED3D_BIND_RENDER_TARGET
Definition: wined3d.h:914
#define WINED3D_FORMAT_ATTR_COMPRESSED
#define WINED3D_FORMAT_CAP_FBO_ATTACHABLE
static BOOL is_identity_fixup(struct color_fixup_desc fixup)
@ WINED3D_GL_RES_TYPE_TEX_2D
@ WINED3D_BLIT_OP_RAW_BLIT
@ WINED3D_BLIT_OP_DEPTH_BLIT
@ WINED3D_BLIT_OP_COLOR_BLIT

Referenced by glsl_blitter_blit().

◆ glsl_blitter_upload_palette()

static void glsl_blitter_upload_palette ( struct wined3d_glsl_blitter *  blitter,
struct wined3d_context_gl *  context_gl,
const struct wined3d_texture_gl *  texture_gl 
)
static

Definition at line 12875 of file glsl_shader.c.

12877{
12878 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
12879 const struct wined3d_palette *palette;
12880
12881 palette = texture_gl->t.swapchain ? texture_gl->t.swapchain->palette : NULL;
12882
12883 if (!blitter->palette_texture)
12884 gl_info->gl_ops.gl.p_glGenTextures(1, &blitter->palette_texture);
12885
12886 wined3d_context_gl_active_texture(context_gl, gl_info, 1);
12887 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D, blitter->palette_texture);
12888 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
12889 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
12890 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
12891
12892 GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
12893 checkGLcall("glBindBuffer");
12894
12895 if (palette)
12896 {
12897 gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 256, 0, GL_BGRA,
12899 }
12900 else
12901 {
12902 static const DWORD black;
12903
12904 FIXME("P8 texture loaded without a palette.\n");
12905 gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, 1, 0, GL_BGRA,
12907 }
12908
12909 wined3d_context_gl_active_texture(context_gl, gl_info, 0);
12910}
void wined3d_context_gl_active_texture(struct wined3d_context_gl *context_gl, const struct wined3d_gl_info *gl_info, unsigned int unit)
Definition: context_gl.c:2489
#define GL_TEXTURE_MIN_FILTER
Definition: gl.h:649
#define GL_TEXTURE_WRAP_S
Definition: gl.h:646
#define GL_BGRA
Definition: gl.h:1485
#define GL_RGB
Definition: gl.h:502
#define GL_NEAREST
Definition: gl.h:678
#define GL_TEXTURE_MAG_FILTER
Definition: gl.h:648
#define GL_TEXTURE_1D
Definition: gl.h:644
#define GL_CLAMP_TO_EDGE
Definition: gl.h:1481
#define GL_UNSIGNED_INT_8_8_8_8_REV
Definition: gl.h:1495
#define GL_PIXEL_UNPACK_BUFFER
Definition: glext.h:477
static HPALETTE palette
Definition: clipboard.c:1457
#define checkGLcall(A)
Definition: wined3d_gl.h:402

Referenced by glsl_blitter_blit().

◆ glsl_fragment_pipe_alloc()

static void * glsl_fragment_pipe_alloc ( const struct wined3d_shader_backend_ops *  shader_backend,
void *  shader_priv 
)
static

Definition at line 12034 of file glsl_shader.c.

12035{
12036 struct shader_glsl_priv *priv;
12037
12038 if (shader_backend == &glsl_shader_backend)
12039 {
12040 priv = shader_priv;
12042 return priv;
12043 }
12044
12045 FIXME("GLSL fragment pipe without GLSL shader backend not implemented.\n");
12046
12047 return NULL;
12048}
int wined3d_ffp_frag_program_key_compare(const void *key, const struct wine_rb_entry *entry)
Definition: utils.c:6436
const struct wined3d_shader_backend_ops glsl_shader_backend
#define wine_rb_init
Definition: rbtree.h:406
struct wine_rb_tree ffp_fragment_shaders
Definition: glsl_shader.c:141

◆ glsl_fragment_pipe_alloc_context_data()

static BOOL glsl_fragment_pipe_alloc_context_data ( struct wined3d_context *  context)
static

Definition at line 12302 of file glsl_shader.c.

12303{
12304 return TRUE;
12305}

◆ glsl_fragment_pipe_alpha_test()

static void glsl_fragment_pipe_alpha_test ( struct wined3d_context_gl *  context_gl,
const struct wined3d_state *  state 
)
static

Definition at line 12176 of file glsl_shader.c.

12178{
12179 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
12180
12181 if (state->render_states[WINED3D_RS_ALPHATESTENABLE])
12182 {
12183 gl_info->gl_ops.gl.p_glEnable(GL_ALPHA_TEST);
12184 checkGLcall("glEnable(GL_ALPHA_TEST)");
12185 }
12186 else
12187 {
12188 gl_info->gl_ops.gl.p_glDisable(GL_ALPHA_TEST);
12189 checkGLcall("glDisable(GL_ALPHA_TEST)");
12190 }
12191}
#define GL_ALPHA_TEST
Definition: gl.h:366
@ WINED3D_RS_ALPHATESTENABLE
Definition: wined3d.h:301

Referenced by shader_glsl_update_legacy_states().

◆ glsl_fragment_pipe_alpha_test_func()

static void glsl_fragment_pipe_alpha_test_func ( struct wined3d_context_gl *  context_gl,
const struct wined3d_state *  state 
)
static

Definition at line 12155 of file glsl_shader.c.

12157{
12159 context_gl->c.device->push_constants[WINED3D_PUSH_CONSTANTS_PS_FFP], &context_gl->c);
12160 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
12162
12163 if (func)
12164 {
12165 gl_info->gl_ops.gl.p_glAlphaFunc(func, constants->alpha_test_ref);
12166 checkGLcall("glAlphaFunc");
12167 }
12168}
void * wined3d_buffer_load_sysmem(struct wined3d_buffer *buffer, struct wined3d_context *context)
Definition: buffer.c:362
GLenum wined3d_gl_compare_func(enum wined3d_cmp_func f)
Definition: ffp_gl.c:138
GLenum func
Definition: glext.h:6028
@ WINED3D_RS_ALPHAFUNC
Definition: wined3d.h:308
@ WINED3D_PUSH_CONSTANTS_PS_FFP

Referenced by shader_glsl_update_legacy_states().

◆ glsl_fragment_pipe_apply_draw_state()

static void glsl_fragment_pipe_apply_draw_state ( struct wined3d_context *  context,
const struct wined3d_state *  state 
)
static

Definition at line 11982 of file glsl_shader.c.

11983{
11984 /* Nothing to do. */
11985}

◆ glsl_fragment_pipe_core_alpha_test()

static void glsl_fragment_pipe_core_alpha_test ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 12170 of file glsl_shader.c.

12172{
12173 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
12174}
@ WINED3D_SHADER_TYPE_PIXEL
Definition: wined3d.h:841

◆ glsl_fragment_pipe_disable()

static void glsl_fragment_pipe_disable ( const struct wined3d_context *  context)
static

Definition at line 11987 of file glsl_shader.c.

11988{
11989}

◆ glsl_fragment_pipe_fog()

static void glsl_fragment_pipe_fog ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 12092 of file glsl_shader.c.

12094{
12095 BOOL use_vshader = use_vs(state) && !state->shader[WINED3D_SHADER_TYPE_VERTEX]->is_ffp_vs;
12096 enum fogsource new_source;
12097 DWORD fogstart = state->render_states[WINED3D_RS_FOGSTART];
12098 DWORD fogend = state->render_states[WINED3D_RS_FOGEND];
12099
12100 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
12101
12102 if (!state->render_states[WINED3D_RS_FOGENABLE])
12103 return;
12104
12105 if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE)
12106 {
12107 if (use_vshader || state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE
12108 || context->stream_info.position_transformed)
12109 new_source = FOGSOURCE_VS;
12110 else
12111 new_source = FOGSOURCE_FFP;
12112 }
12113 else
12114 {
12115 new_source = FOGSOURCE_FFP;
12116 }
12117
12118 if (new_source != context->fog_source || fogstart == fogend)
12119 {
12120 context->fog_source = new_source;
12121 context->constant_update_mask |= WINED3D_SHADER_CONST_PS_FOG;
12122 }
12123}
@ WINED3D_FOG_NONE
Definition: wined3d.h:480
@ WINED3D_RS_FOGEND
Definition: wined3d.h:320
@ WINED3D_RS_FOGSTART
Definition: wined3d.h:319
@ WINED3D_RS_FOGTABLEMODE
Definition: wined3d.h:318
@ WINED3D_RS_FOGENABLE
Definition: wined3d.h:311
@ WINED3D_RS_FOGVERTEXMODE
Definition: wined3d.h:350
@ WINED3D_SHADER_TYPE_VERTEX
Definition: wined3d.h:842
static BOOL use_vs(const struct wined3d_state *state)
fogsource
@ FOGSOURCE_VS
@ FOGSOURCE_FFP
#define WINED3D_SHADER_CONST_PS_FOG

Referenced by glsl_fragment_pipe_vdecl().

◆ glsl_fragment_pipe_fogparams()

static void glsl_fragment_pipe_fogparams ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 12086 of file glsl_shader.c.

12088{
12089 context->constant_update_mask |= WINED3D_SHADER_CONST_PS_FOG;
12090}

◆ glsl_fragment_pipe_free()

static void glsl_fragment_pipe_free ( struct wined3d_device *  device,
struct wined3d_context *  context 
)
static

Definition at line 12069 of file glsl_shader.c.

12070{
12071 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
12072 struct shader_glsl_priv *priv = device->fragment_priv;
12074
12075 ctx.priv = priv;
12076 ctx.context_gl = context_gl;
12078}
static void shader_glsl_free_ffp_fragment_shader(struct wine_rb_entry *entry, void *param)
struct shader_glsl_priv * priv
Definition: glsl_shader.c:347
const struct wined3d_context_gl * context_gl
Definition: glsl_shader.c:348

◆ glsl_fragment_pipe_free_context_data()

static void glsl_fragment_pipe_free_context_data ( struct wined3d_context *  context)
static

Definition at line 12307 of file glsl_shader.c.

12308{
12309}

◆ glsl_fragment_pipe_get_caps()

static void glsl_fragment_pipe_get_caps ( const struct wined3d_adapter *  adapter,
struct fragment_caps *  caps 
)
static

Definition at line 11991 of file glsl_shader.c.

11992{
11993 const struct wined3d_gl_info *gl_info = &wined3d_adapter_gl_const(adapter)->gl_info;
11994
11995 memset(caps, 0, sizeof(*caps));
12025}
return adapter
unsigned int max_blend_stages
unsigned int PrimitiveMiscCaps
unsigned int max_textures
unsigned int TextureOpCaps
#define WINED3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
Definition: wined3d.h:1171
#define WINED3DTEXOPCAPS_ADD
Definition: wined3d.h:1160
#define WINED3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
Definition: wined3d.h:1172
#define WINED3DTEXOPCAPS_BLENDDIFFUSEALPHA
Definition: wined3d.h:1165
#define WINED3DPMISCCAPS_PERSTAGECONSTANT
Definition: wined3d.h:1114
#define WINED3DTEXOPCAPS_BUMPENVMAPLUMINANCE
Definition: wined3d.h:1176
#define WINED3DTEXOPCAPS_BLENDTEXTUREALPHA
Definition: wined3d.h:1166
#define WINED3DTEXOPCAPS_MODULATE2X
Definition: wined3d.h:1158
#define WINED3DTEXOPCAPS_DISABLE
Definition: wined3d.h:1154
#define WINED3DTEXOPCAPS_SELECTARG1
Definition: wined3d.h:1155
#define WINED3DTEXOPCAPS_SUBTRACT
Definition: wined3d.h:1163
#define WINED3DTEXOPCAPS_BUMPENVMAP
Definition: wined3d.h:1175
#define WINED3DTEXOPCAPS_ADDSIGNED2X
Definition: wined3d.h:1162
#define WINED3DTEXOPCAPS_MODULATE4X
Definition: wined3d.h:1159
#define WINED3DTEXOPCAPS_ADDSMOOTH
Definition: wined3d.h:1164
#define WINED3DPMISCCAPS_TSSARGTEMP
Definition: wined3d.h:1110
#define WINED3DTEXOPCAPS_MULTIPLYADD
Definition: wined3d.h:1178
#define WINED3DTEXOPCAPS_BLENDFACTORALPHA
Definition: wined3d.h:1167
#define WINED3DTEXOPCAPS_ADDSIGNED
Definition: wined3d.h:1161
#define WINED3D_MAX_FFP_TEXTURES
Definition: wined3d.h:1597
#define WINED3DTEXOPCAPS_DOTPRODUCT3
Definition: wined3d.h:1177
#define WINED3DTEXOPCAPS_LERP
Definition: wined3d.h:1179
#define WINED3DTEXOPCAPS_BLENDTEXTUREALPHAPM
Definition: wined3d.h:1168
#define WINED3DTEXOPCAPS_SELECTARG2
Definition: wined3d.h:1156
#define WINED3DTEXOPCAPS_MODULATE
Definition: wined3d.h:1157
#define WINED3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
Definition: wined3d.h:1174
#define WINED3DTEXOPCAPS_BLENDCURRENTALPHA
Definition: wined3d.h:1169
#define WINED3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
Definition: wined3d.h:1173
static const struct wined3d_adapter_gl * wined3d_adapter_gl_const(const struct wined3d_adapter *adapter)
Definition: wined3d_gl.h:811

◆ glsl_fragment_pipe_get_emul_mask()

static unsigned int glsl_fragment_pipe_get_emul_mask ( const struct wined3d_adapter *  adapter)
static

Definition at line 12027 of file glsl_shader.c.

12028{
12031 return 0;
12032}
#define GL_EXT_EMUL_ARB_MULTITEXTURE

◆ glsl_fragment_pipe_shademode()

static void glsl_fragment_pipe_shademode ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 12193 of file glsl_shader.c.

12195{
12196 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
12197}

◆ glsl_fragment_pipe_shader()

static void glsl_fragment_pipe_shader ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 12080 of file glsl_shader.c.

12082{
12083 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
12084}

◆ glsl_fragment_pipe_tex_transform()

static void glsl_fragment_pipe_tex_transform ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 12148 of file glsl_shader.c.

12150{
12151 /* Because of args->tex_transform. */
12152 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
12153}

◆ glsl_fragment_pipe_vdecl()

static void glsl_fragment_pipe_vdecl ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 12125 of file glsl_shader.c.

12127{
12128 const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info;
12129
12130 /* Because of settings->texcoords_initialized and args->texcoords_initialized. */
12131 if (!shader_glsl_full_ffp_varyings(gl_info))
12132 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
12133
12136}
static unsigned int shader_glsl_full_ffp_varyings(const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:416
static void glsl_fragment_pipe_fog(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
static bool isStateDirty(const struct wined3d_context *context, unsigned int state_id)
#define STATE_RENDER(a)

◆ glsl_fragment_pipe_vs()

static void glsl_fragment_pipe_vs ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 12138 of file glsl_shader.c.

12140{
12141 const struct wined3d_gl_info *gl_info = wined3d_context_gl(context)->gl_info;
12142
12143 /* Because of settings->texcoords_initialized and args->texcoords_initialized. */
12144 if (!shader_glsl_full_ffp_varyings(gl_info))
12145 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
12146}

◆ glsl_free_blitter_program()

static void glsl_free_blitter_program ( struct wine_rb_entry *  entry,
void *  ctx 
)
static

Definition at line 12371 of file glsl_shader.c.

12372{
12374 struct wined3d_context_gl *context_gl = ctx;
12375 const struct wined3d_gl_info *gl_info;
12376
12377 gl_info = context_gl->gl_info;
12378 GL_EXTCALL(glDeleteProgram(program->id));
12379 checkGLcall("glDeleteProgram()");
12380 free(program);
12381}

Referenced by glsl_blitter_destroy().

◆ glsl_is_color_reg_read()

static BOOL glsl_is_color_reg_read ( const struct wined3d_shader *  shader,
unsigned int  idx 
)
static

Definition at line 2298 of file glsl_shader.c.

2299{
2300 const struct wined3d_shader_signature *input_signature = &shader->input_signature;
2301 const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
2302 DWORD input_reg_used = shader->u.ps.input_reg_used;
2303 unsigned int i;
2304
2305 if (reg_maps->shader_version.major < 3)
2306 return input_reg_used & (1u << idx);
2307
2308 for (i = 0; i < input_signature->element_count; ++i)
2309 {
2310 const struct wined3d_shader_signature_element *input = &input_signature->elements[i];
2311
2312 if (!(reg_maps->input_registers & (1u << input->register_idx)))
2313 continue;
2314
2316 && input->semantic_idx == idx)
2317 return input_reg_used & (1u << input->register_idx);
2318 }
2319 return FALSE;
2320}
BOOL shader_match_semantic(const char *semantic_name, enum wined3d_decl_usage usage)
Definition: shader.c:366
unsigned int idx
Definition: utils.c:40
GLenum GLenum GLenum input
Definition: glext.h:9031
struct wined3d_shader_version shader_version
union wined3d_shader_reg_maps::@346 u
struct wined3d_shader_signature_element * elements
@ WINED3D_DECL_USAGE_COLOR
Definition: wined3d.h:817

Referenced by shader_glsl_generate_fragment_shader().

◆ glsl_primitive_type_from_d3d()

static const char * glsl_primitive_type_from_d3d ( enum wined3d_primitive_type  primitive_type)
static

Definition at line 2267 of file glsl_shader.c.

2268{
2269 switch (primitive_type)
2270 {
2272 return "points";
2273
2275 return "lines";
2276
2278 return "line_strip";
2279
2281 return "triangles";
2282
2284 return "triangle_strip";
2285
2287 return "lines_adjacency";
2288
2290 return "triangles_adjacency";
2291
2292 default:
2293 FIXME("Unhandled primitive type %s.\n", debug_d3dprimitivetype(primitive_type));
2294 return "";
2295 }
2296}
const char * debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type)
Definition: utils.c:5009
@ WINED3D_PT_LINELIST
Definition: wined3d.h:77
@ WINED3D_PT_POINTLIST
Definition: wined3d.h:76
@ WINED3D_PT_TRIANGLELIST_ADJ
Definition: wined3d.h:84
@ WINED3D_PT_LINELIST_ADJ
Definition: wined3d.h:82
@ WINED3D_PT_TRIANGLESTRIP
Definition: wined3d.h:80
@ WINED3D_PT_LINESTRIP
Definition: wined3d.h:78
@ WINED3D_PT_TRIANGLELIST
Definition: wined3d.h:79

Referenced by shader_glsl_generate_geometry_shader().

◆ glsl_program_key_compare()

static int glsl_program_key_compare ( const void *  key,
const struct wine_rb_entry *  entry 
)
static

Definition at line 11164 of file glsl_shader.c.

11165{
11166 const struct glsl_program_key *k = key;
11169 int ret;
11170
11171 if ((ret = wined3d_uint32_compare(k->vs_id, prog->vs.id)))
11172 return ret;
11173 if ((ret = wined3d_uint32_compare(k->gs_id, prog->gs.id)))
11174 return ret;
11175 if ((ret = wined3d_uint32_compare(k->ps_id, prog->ps.id)))
11176 return ret;
11177 if ((ret = wined3d_uint32_compare(k->hs_id, prog->hs.id)))
11178 return ret;
11179 if ((ret = wined3d_uint32_compare(k->ds_id, prog->ds.id)))
11180 return ret;
11181 if ((ret = wined3d_uint32_compare(k->cs_id, prog->cs.id)))
11182 return ret;
11183
11184 return 0;
11185}
char * prog
Definition: isohybrid.c:47
int k
Definition: mpi.c:3369
static int wined3d_uint32_compare(uint32_t x, uint32_t y)

Referenced by shader_glsl_alloc().

◆ glsl_vertex_pipe_clip_plane()

static void glsl_vertex_pipe_clip_plane ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 11897 of file glsl_shader.c.

11899{
11900 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
11901 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
11902 UINT index = state_id - STATE_CLIPPLANE(0);
11903
11904 if (index >= gl_info->limits.user_clip_distances)
11905 return;
11906
11907 context->constant_update_mask |= WINED3D_SHADER_CONST_VS_CLIP_PLANES;
11908}
GLuint index
Definition: glext.h:6031
#define STATE_CLIPPLANE(a)
#define WINED3D_SHADER_CONST_VS_CLIP_PLANES

◆ glsl_vertex_pipe_geometry_shader()

static void glsl_vertex_pipe_geometry_shader ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 11849 of file glsl_shader.c.

11851{
11852 struct glsl_context_data *ctx_data = context->shader_backend_data;
11854
11857 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
11859
11860 if (state->shader[WINED3D_SHADER_TYPE_DOMAIN])
11861 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_DOMAIN;
11862 else if (state->shader[WINED3D_SHADER_TYPE_VERTEX]
11863 && state->shader[WINED3D_SHADER_TYPE_VERTEX]->reg_maps.shader_version.major >= 4)
11864 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
11865}
BOOL rasterization_disabled
Definition: glsl_shader.c:280
@ WINED3D_SHADER_TYPE_GEOMETRY
Definition: wined3d.h:843
@ WINED3D_SHADER_TYPE_DOMAIN
Definition: wined3d.h:845
static BOOL is_rasterization_disabled(const struct wined3d_shader *geometry_shader)

◆ glsl_vertex_pipe_hs()

static void glsl_vertex_pipe_hs ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 11837 of file glsl_shader.c.

11839{
11840 /* In Direct3D tessellator options (e.g. output primitive type, primitive
11841 * winding) are defined in Hull Shaders, while in GLSL those are
11842 * specified in Tessellation Evaluation Shaders. */
11843 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_DOMAIN;
11844
11845 if (state->shader[WINED3D_SHADER_TYPE_VERTEX])
11846 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
11847}

◆ glsl_vertex_pipe_nop()

static void glsl_vertex_pipe_nop ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 11792 of file glsl_shader.c.

11793 {}

◆ glsl_vertex_pipe_pixel_shader()

static void glsl_vertex_pipe_pixel_shader ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 11867 of file glsl_shader.c.

11869{
11871 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_GEOMETRY;
11872 else if (state->shader[WINED3D_SHADER_TYPE_DOMAIN])
11873 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_DOMAIN;
11874 else if (state->shader[WINED3D_SHADER_TYPE_VERTEX]
11875 && state->shader[WINED3D_SHADER_TYPE_VERTEX]->reg_maps.shader_version.major >= 4)
11876 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
11877}

◆ glsl_vertex_pipe_pointsize()

static void glsl_vertex_pipe_pointsize ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 11885 of file glsl_shader.c.

11887{
11888 context->constant_update_mask |= WINED3D_SHADER_CONST_VS_POINTSIZE;
11889}
#define WINED3D_SHADER_CONST_VS_POINTSIZE

◆ glsl_vertex_pipe_shademode()

static void glsl_vertex_pipe_shademode ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 11891 of file glsl_shader.c.

11893{
11894 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
11895}

◆ glsl_vertex_pipe_shader()

static void glsl_vertex_pipe_shader ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 11795 of file glsl_shader.c.

11797{
11798 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
11799}

◆ glsl_vertex_pipe_vdecl()

static void glsl_vertex_pipe_vdecl ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 11801 of file glsl_shader.c.

11803{
11804 BOOL transformed = context->stream_info.position_transformed;
11805 BOOL wasrhw = context->last_was_rhw;
11806
11807 context->last_was_rhw = transformed;
11808
11809 /* If the vertex declaration contains a transformed position attribute,
11810 * the draw uses the fixed function vertex pipeline regardless of any
11811 * vertex shader set by the application. */
11812 if (transformed != wasrhw
11813 || context->stream_info.swizzle_map != context->last_swizzle_map)
11814 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
11815
11816 context->last_swizzle_map = context->stream_info.swizzle_map;
11817
11818 if (!use_vs(state))
11819 {
11820 /* Because of args->tex_transform. */
11821 if (use_ps(state)
11822 && state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.shader_version.major == 1
11823 && state->shader[WINED3D_SHADER_TYPE_PIXEL]->reg_maps.shader_version.minor <= 3)
11824 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_PIXEL;
11825 }
11826}
static BOOL use_ps(const struct wined3d_state *state)

◆ glsl_vertex_pipe_viewport()

static void glsl_vertex_pipe_viewport ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 11879 of file glsl_shader.c.

11881{
11883}
#define WINED3D_SHADER_CONST_FFP_PROJ
#define WINED3D_SHADER_CONST_POS_FIXUP

◆ glsl_vertex_pipe_vp_alloc()

static void * glsl_vertex_pipe_vp_alloc ( const struct wined3d_shader_backend_ops *  shader_backend,
void *  shader_priv 
)
static

Definition at line 11746 of file glsl_shader.c.

11747{
11748 struct shader_glsl_priv *priv;
11749
11750 if (shader_backend == &glsl_shader_backend)
11751 {
11752 priv = shader_priv;
11754 return priv;
11755 }
11756
11757 FIXME("GLSL vertex pipe without GLSL shader backend not implemented.\n");
11758
11759 return NULL;
11760}
int wined3d_ffp_vertex_program_key_compare(const void *key, const struct wine_rb_entry *entry)
Definition: utils.c:6579
struct wine_rb_tree ffp_vertex_shaders
Definition: glsl_shader.c:140

◆ glsl_vertex_pipe_vp_apply_draw_state()

static void glsl_vertex_pipe_vp_apply_draw_state ( struct wined3d_context *  context,
const struct wined3d_state *  state 
)
static

Definition at line 11713 of file glsl_shader.c.

11713{}

◆ glsl_vertex_pipe_vp_disable()

static void glsl_vertex_pipe_vp_disable ( const struct wined3d_context *  context)
static

Definition at line 11715 of file glsl_shader.c.

11715{}

◆ glsl_vertex_pipe_vp_free()

static void glsl_vertex_pipe_vp_free ( struct wined3d_device *  device,
struct wined3d_context *  context 
)
static

Definition at line 11781 of file glsl_shader.c.

11782{
11783 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
11784 struct shader_glsl_priv *priv = device->vertex_priv;
11786
11787 ctx.priv = priv;
11788 ctx.context_gl = context_gl;
11790}
static void shader_glsl_free_ffp_vertex_shader(struct wine_rb_entry *entry, void *param)

◆ glsl_vertex_pipe_vp_get_caps()

static void glsl_vertex_pipe_vp_get_caps ( const struct wined3d_adapter *  adapter,
struct wined3d_vertex_caps *  caps 
)
static

Definition at line 11717 of file glsl_shader.c.

11718{
11719 const struct wined3d_gl_info *gl_info = &wined3d_adapter_gl_const(adapter)->gl_info;
11720
11721 memset(caps, 0, sizeof(*caps));
11722
11734 caps->fvf_caps = WINED3DFVFCAPS_PSIZE | 8; /* 8 texture coordinates. */
11735 caps->max_user_clip_planes = gl_info->limits.user_clip_distances;
11737}
#define WINED3DPRASTERCAPS_FOGRANGE
Definition: wined3d.h:1213
#define WINED3DVTXPCAPS_LOCALVIEWER
Definition: wined3d.h:1289
#define WINED3DVTXPCAPS_POSITIONALLIGHTS
Definition: wined3d.h:1288
#define WINED3DVTXPCAPS_TEXGEN
Definition: wined3d.h:1284
#define WINED3DVTXPCAPS_MATERIALSOURCE7
Definition: wined3d.h:1285
#define WINED3DVTXPCAPS_VERTEXFOG
Definition: wined3d.h:1286
#define WINED3DFVFCAPS_PSIZE
Definition: wined3d.h:1066
#define WINED3DVTXPCAPS_TEXGEN_SPHEREMAP
Definition: wined3d.h:1291
#define WINED3DVTXPCAPS_DIRECTIONALLIGHTS
Definition: wined3d.h:1287
#define WINED3D_MAX_ACTIVE_LIGHTS
#define MAX_VERTEX_BLENDS

◆ glsl_vertex_pipe_vp_get_emul_mask()

static unsigned int glsl_vertex_pipe_vp_get_emul_mask ( const struct wined3d_adapter *  adapter)
static

Definition at line 11739 of file glsl_shader.c.

11740{
11743 return 0;
11744}

◆ glsl_vertex_pipe_vs()

static void glsl_vertex_pipe_vs ( struct wined3d_context *  context,
const struct wined3d_state *  state,
DWORD  state_id 
)
static

Definition at line 11828 of file glsl_shader.c.

11830{
11831 context->shader_update_mask |= 1u << WINED3D_SHADER_TYPE_VERTEX;
11832 /* Different vertex shaders potentially require a different vertex attributes setup. */
11835}
static void context_apply_state(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
#define STATE_VDECL

◆ is_mipmapped()

static BOOL is_mipmapped ( enum wined3d_shader_resource_type  resource_type)
static

Definition at line 6027 of file glsl_shader.c.

6028{
6029 return resource_type != WINED3D_SHADER_RESOURCE_BUFFER && !is_multisampled(resource_type);
6030}
static BOOL is_multisampled(enum wined3d_shader_resource_type resource_type)
Definition: glsl_shader.c:6021
@ WINED3D_SHADER_RESOURCE_BUFFER

Referenced by shader_glsl_ld(), and shader_glsl_resinfo().

◆ is_multisampled()

static BOOL is_multisampled ( enum wined3d_shader_resource_type  resource_type)
static

Definition at line 6021 of file glsl_shader.c.

6022{
6023 return resource_type == WINED3D_SHADER_RESOURCE_TEXTURE_2DMS
6025}
@ WINED3D_SHADER_RESOURCE_TEXTURE_2DMSARRAY
@ WINED3D_SHADER_RESOURCE_TEXTURE_2DMS

Referenced by is_mipmapped(), and shader_glsl_ld().

◆ needs_interpolation_qualifiers_for_shader_outputs()

static BOOL needs_interpolation_qualifiers_for_shader_outputs ( const struct wined3d_gl_info *  gl_info)
static

Definition at line 2211 of file glsl_shader.c.

2212{
2213 /* In GLSL 4.40+ it is fine to specify interpolation qualifiers only in
2214 * fragment shaders. In older GLSL versions interpolation qualifiers must
2215 * match between shader stages. */
2216 return gl_info->glsl_version < MAKEDWORD_VERSION(4, 40);
2217}
unsigned int glsl_version
Definition: wined3d_gl.h:343
#define MAKEDWORD_VERSION(maj, min)

Referenced by shader_glsl_declare_shader_outputs(), and shader_glsl_get_caps().

◆ needs_legacy_glsl_syntax()

◆ print_glsl_info_log()

void print_glsl_info_log ( const struct wined3d_gl_info *  gl_info,
GLuint  id,
BOOL  program 
)

Definition at line 485 of file glsl_shader.c.

486{
487 int length = 0;
488 char *log;
489
490 if (!WARN_ON(d3d_shader) && !FIXME_ON(d3d_shader))
491 return;
492
493 if (program)
494 GL_EXTCALL(glGetProgramiv(id, GL_INFO_LOG_LENGTH, &length));
495 else
496 GL_EXTCALL(glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length));
497
498 /* A size of 1 is just a null-terminated string, so the log should be bigger than
499 * that if there are errors. */
500 if (length > 1)
501 {
502 const char *ptr, *end, *line;
503
504 log = malloc(length);
505 if (program)
506 GL_EXTCALL(glGetProgramInfoLog(id, length, NULL, log));
507 else
508 GL_EXTCALL(glGetShaderInfoLog(id, length, NULL, log));
509
510 ptr = log;
511 /* The info log is supposed to be zero-terminated. Note that at least
512 * some versions of fglrx don't terminate the string properly. The
513 * reported length does include the supposed terminator though, so we
514 * don't care here. */
515 end = &ptr[length - 1];
516 if (gl_info->quirks & WINED3D_QUIRK_INFO_LOG_SPAM)
517 {
518 WARN("Info log received from GLSL shader #%u:\n", id);
519 while ((line = wined3d_get_line(&ptr, end)))
520 {
521 WARN(" %.*s", (int)(ptr - line), line);
522 }
523 }
524 else
525 {
526 FIXME("Info log received from GLSL shader #%u:\n", id);
527 while ((line = wined3d_get_line(&ptr, end)))
528 {
529 FIXME(" %.*s", (int)(ptr - line), line);
530 }
531 }
532 free(log);
533 }
534}
GLuint GLuint end
Definition: gl.h:1545
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
#define GL_INFO_LOG_LENGTH
Definition: glext.h:450
#define WARN_ON(c)
Definition: module.h:257
#define FIXME_ON(ch)
Definition: debug.h:418
#define log(outFile, fmt,...)
Definition: util.h:15
Definition: parser.c:49
uint32_t quirks
Definition: wined3d_gl.h:346
#define WINED3D_QUIRK_INFO_LOG_SPAM
Definition: wined3d_gl.h:328
static const char * wined3d_get_line(const char **ptr, const char *end)

Referenced by draw_test_quad(), glsl_blitter_generate_program(), shader_glsl_compile(), shader_glsl_generate_vkd3d_shader(), and shader_glsl_validate_link().

◆ PRINTF_ATTR() [1/2]

static void PRINTF_ATTR ( 4  ,
5   
)
static

Definition at line 2108 of file glsl_shader.c.

2110{
2111 va_list args;
2112 int ret;
2113
2114 shader_addline(buffer, "%s%s ", flat ? "flat " : "",
2115 needs_legacy_glsl_syntax(gl_info) ? "varying" : "in");
2116 for (;;)
2117 {
2120 va_end(args);
2121 if (!ret)
2122 return;
2124 return;
2125 }
2126}
int shader_vaddline(struct wined3d_string_buffer *buffer, const char *format, va_list args)
Definition: shader.c:453
BOOL string_buffer_resize(struct wined3d_string_buffer *buffer, int rc)
Definition: shader.c:435
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
char * va_list
Definition: vadefs.h:50

◆ PRINTF_ATTR() [2/2]

static void PRINTF_ATTR ( 9  ,
10   
)
static

Definition at line 3796 of file glsl_shader.c.

3800{
3801 const struct wined3d_shader_version *version = &ins->ctx->reg_maps->shader_version;
3802 char dst_swizzle[6];
3803 struct color_fixup_desc fixup;
3804 va_list args;
3805 int ret;
3806
3807 shader_glsl_swizzle_to_str(swizzle, FALSE, ins->dst[0].write_mask, dst_swizzle);
3808
3809 /* If ARB_texture_swizzle is supported we don't need to do anything here.
3810 * We actually rely on it for vertex shaders and SM4+. */
3811 if (version->type == WINED3D_SHADER_TYPE_PIXEL && version->major < 4)
3812 {
3813 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
3814 fixup = priv->cur_ps_args->color_fixup[sampler_bind_idx];
3815 }
3816 else
3817 {
3818 fixup = COLOR_FIXUP_IDENTITY;
3819 }
3820
3821 shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &ins->dst[0], 0, sample_function->data_type);
3822
3823 if (sample_function->output_single_component)
3824 shader_addline(ins->ctx->buffer, "vec4(");
3825
3826 shader_addline(ins->ctx->buffer, "%s(%s_sampler%u, ",
3827 sample_function->name->buffer, shader_glsl_get_prefix(version->type), sampler_bind_idx);
3828
3829 for (;;)
3830 {
3831 va_start(args, coord_reg_fmt);
3832 ret = shader_vaddline(ins->ctx->buffer, coord_reg_fmt, args);
3833 va_end(args);
3834 if (!ret)
3835 break;
3836 if (!string_buffer_resize(ins->ctx->buffer, ret))
3837 break;
3838 }
3839
3840 if (dx && dy)
3841 shader_addline(ins->ctx->buffer, ", %s, %s", dx, dy);
3842 else if (bias)
3843 shader_addline(ins->ctx->buffer, ", %s", bias);
3844 if (sample_function->offset_size)
3845 {
3846 int offset_immdata[4] = {offset->u, offset->v, offset->w};
3847 shader_addline(ins->ctx->buffer, ", ");
3848 shader_glsl_append_imm_ivec(ins->ctx->buffer, offset_immdata, sample_function->offset_size);
3849 }
3850 shader_addline(ins->ctx->buffer, ")");
3851
3852 if (sample_function->output_single_component)
3853 shader_addline(ins->ctx->buffer, ")");
3854
3855 shader_addline(ins->ctx->buffer, "%s);\n", dst_swizzle);
3856
3857 if (!is_identity_fixup(fixup))
3858 shader_glsl_color_correction(ins, fixup);
3859}
static const WCHAR version[]
Definition: asmname.c:66
GLfloat bias
Definition: glext.h:7909
GLintptr offset
Definition: glext.h:5920
static DWORD shader_glsl_append_dst_ext(struct wined3d_string_buffer *buffer, const struct wined3d_shader_instruction *ins, const struct wined3d_shader_dst_param *dst, unsigned int dst_idx, enum wined3d_data_type data_type)
Definition: glsl_shader.c:3486
static const char * shader_glsl_get_prefix(enum wined3d_shader_type type)
Definition: glsl_shader.c:370
static void shader_glsl_color_correction(const struct wined3d_shader_instruction *ins, struct color_fixup_desc fixup)
Definition: glsl_shader.c:3785
static void shader_glsl_swizzle_to_str(DWORD swizzle, BOOL fixup, DWORD mask, char *str)
Definition: glsl_shader.c:3317
static void shader_glsl_append_imm_ivec(struct wined3d_string_buffer *buffer, const int *values, unsigned int size)
Definition: glsl_shader.c:463
GLint dy
Definition: linetemp.h:97
GLint dx
Definition: linetemp.h:97
const struct ps_compile_args * cur_ps_args
Definition: glsl_shader.c:272
static const struct color_fixup_desc COLOR_FIXUP_IDENTITY

◆ reset_program_constant_version()

static void reset_program_constant_version ( struct wine_rb_entry *  entry,
void *  context 
)
static

Definition at line 1475 of file glsl_shader.c.

1476{
1477 WINE_RB_ENTRY_VALUE(entry, struct glsl_shader_prog_link, program_lookup_entry)->constant_version = 0;
1478}

Referenced by shader_glsl_load_constants().

◆ set_glsl_compute_shader_program()

static void set_glsl_compute_shader_program ( const struct wined3d_context_gl *  context_gl,
const struct wined3d_state *  state,
struct shader_glsl_priv *  priv,
struct glsl_context_data *  ctx_data 
)
static

Definition at line 10371 of file glsl_shader.c.

10373{
10375 struct wined3d_shader *shader;
10376 struct glsl_program_key key;
10377 GLuint cs_id;
10378
10379 if (!(context_gl->c.shader_update_mask & (1u << WINED3D_SHADER_TYPE_COMPUTE)))
10380 return;
10381
10382 if (!(shader = state->shader[WINED3D_SHADER_TYPE_COMPUTE]))
10383 {
10384 WARN("Compute shader is NULL.\n");
10385 ctx_data->glsl_program = NULL;
10386 return;
10387 }
10388
10389 cs_id = find_glsl_compute_shader(context_gl, priv, shader);
10390 memset(&key, 0, sizeof(key));
10391 key.cs_id = cs_id;
10392 if (!(entry = get_glsl_program_entry(priv, &key)))
10393 ERR("Failed to find GLSL program for compute shader %p.\n", shader);
10394 ctx_data->glsl_program = entry;
10395}
static GLuint find_glsl_compute_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, struct wined3d_shader *shader)
static struct glsl_shader_prog_link * get_glsl_program_entry(const struct shader_glsl_priv *priv, const struct glsl_program_key *key)
Definition: glsl_shader.c:7059
struct glsl_shader_prog_link * glsl_program
Definition: glsl_shader.c:278
@ WINED3D_SHADER_TYPE_COMPUTE
Definition: wined3d.h:848

Referenced by shader_glsl_update_compute_program().

◆ set_glsl_shader_program()

static void set_glsl_shader_program ( const struct wined3d_context_gl *  context_gl,
const struct wined3d_state *  state,
struct shader_glsl_priv *  priv,
struct glsl_context_data *  ctx_data 
)
static

Definition at line 10398 of file glsl_shader.c.

10400{
10401 const struct wined3d_d3d_info *d3d_info = context_gl->c.d3d_info;
10402 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
10403 const struct wined3d_shader *pre_rasterization_shader;
10404 struct wined3d_shader *hshader, *dshader, *gshader;
10406 struct wined3d_shader *vshader = NULL;
10407 struct wined3d_shader *pshader = NULL;
10408 GLuint reorder_shader_id = 0;
10409 struct glsl_program_key key;
10410 uint32_t attribs_map;
10411 GLuint program_id;
10412 unsigned int i;
10413 GLuint vs_id = 0;
10414 GLuint hs_id = 0;
10415 GLuint ds_id = 0;
10416 GLuint gs_id = 0;
10417 GLuint ps_id = 0;
10418 struct list *ps_list, *vs_list;
10420
10421 if (!(context_gl->c.shader_update_mask & (1u << WINED3D_SHADER_TYPE_VERTEX)) && ctx_data->glsl_program)
10422 {
10423 vs_id = ctx_data->glsl_program->vs.id;
10424 vs_list = &ctx_data->glsl_program->vs.shader_entry;
10425
10426 if (use_vs(state) || d3d_info->ffp_hlsl)
10427 vshader = state->shader[WINED3D_SHADER_TYPE_VERTEX];
10428 }
10429 else if (use_vs(state) || d3d_info->ffp_hlsl)
10430 {
10432
10433 vshader = state->shader[WINED3D_SHADER_TYPE_VERTEX];
10434
10435 find_vs_compile_args(state, vshader, &vs_compile_args, &context_gl->c);
10436 vs_id = find_glsl_vertex_shader(context_gl, priv, vshader, &vs_compile_args);
10437 vs_list = &vshader->linked_programs;
10438 }
10439 else if (priv->vertex_pipe == &glsl_vertex_pipe)
10440 {
10441 struct glsl_ffp_vertex_shader *ffp_shader;
10443
10444 wined3d_ffp_get_vs_settings(state, &context_gl->c.stream_info, d3d_info, &settings);
10445 ffp_shader = shader_glsl_find_ffp_vertex_shader(priv, gl_info, &settings);
10446 vs_id = ffp_shader->id;
10447 vs_list = &ffp_shader->linked_programs;
10448 }
10449
10450 hshader = state->shader[WINED3D_SHADER_TYPE_HULL];
10451 if (!(context_gl->c.shader_update_mask & (1u << WINED3D_SHADER_TYPE_HULL)) && ctx_data->glsl_program)
10452 hs_id = ctx_data->glsl_program->hs.id;
10453 else if (hshader)
10454 hs_id = find_glsl_hull_shader(context_gl, priv, hshader);
10455
10456 dshader = state->shader[WINED3D_SHADER_TYPE_DOMAIN];
10457 if (!(context_gl->c.shader_update_mask & (1u << WINED3D_SHADER_TYPE_DOMAIN)) && ctx_data->glsl_program)
10458 {
10459 ds_id = ctx_data->glsl_program->ds.id;
10460 }
10461 else if (dshader)
10462 {
10463 struct ds_compile_args args;
10464
10465 find_ds_compile_args(state, dshader, &args, &context_gl->c);
10466 ds_id = find_glsl_domain_shader(context_gl, priv, dshader, &args);
10467 }
10468
10469 gshader = state->shader[WINED3D_SHADER_TYPE_GEOMETRY];
10470 if (!(context_gl->c.shader_update_mask & (1u << WINED3D_SHADER_TYPE_GEOMETRY)) && ctx_data->glsl_program)
10471 {
10472 gs_id = ctx_data->glsl_program->gs.id;
10473 }
10474 else if (gshader)
10475 {
10476 struct gs_compile_args args;
10477
10478 find_gs_compile_args(state, gshader, &args, &context_gl->c);
10479 gs_id = find_glsl_geometry_shader(context_gl, priv, gshader, &args);
10480 }
10481
10482 /* A pixel shader is not used when rasterization is disabled. */
10483 if (is_rasterization_disabled(gshader))
10484 {
10485 ps_id = 0;
10486 ps_list = NULL;
10487 }
10488 else if (!(context_gl->c.shader_update_mask & (1u << WINED3D_SHADER_TYPE_PIXEL)) && ctx_data->glsl_program)
10489 {
10490 ps_id = ctx_data->glsl_program->ps.id;
10491 ps_list = &ctx_data->glsl_program->ps.shader_entry;
10492
10493 if (use_ps(state))
10494 pshader = state->shader[WINED3D_SHADER_TYPE_PIXEL];
10495 }
10496 else if (use_ps(state))
10497 {
10499 pshader = state->shader[WINED3D_SHADER_TYPE_PIXEL];
10500 find_ps_compile_args(state, pshader, context_gl->c.stream_info.position_transformed,
10501 &ps_compile_args, &context_gl->c);
10502 ps_id = find_glsl_fragment_shader(context_gl, priv, pshader, &ps_compile_args);
10503 ps_list = &pshader->linked_programs;
10504 }
10505 else if (priv->fragment_pipe == &glsl_fragment_pipe
10506 && !(vshader && vshader->reg_maps.shader_version.major >= 4))
10507 {
10508 struct glsl_ffp_fragment_shader *ffp_shader;
10510
10512 ffp_shader = shader_glsl_find_ffp_fragment_shader(priv, &settings, context_gl);
10513 ps_id = ffp_shader->id;
10514 ps_list = &ffp_shader->linked_programs;
10515 }
10516
10517 key.vs_id = vs_id;
10518 key.hs_id = hs_id;
10519 key.ds_id = ds_id;
10520 key.gs_id = gs_id;
10521 key.ps_id = ps_id;
10522 key.cs_id = 0;
10523 if ((!vs_id && !hs_id && !ds_id && !gs_id && !ps_id) || (entry = get_glsl_program_entry(priv, &key)))
10524 {
10525 ctx_data->glsl_program = entry;
10526 return;
10527 }
10528
10529 /* If we get to this point, then no matching program exists, so we create one */
10530 program_id = GL_EXTCALL(glCreateProgram());
10531 TRACE("Created new GLSL shader program %u.\n", program_id);
10532
10533 /* Create the entry */
10534 entry = malloc(sizeof(*entry));
10535 entry->id = program_id;
10536 entry->vs.id = vs_id;
10537 entry->hs.id = hs_id;
10538 entry->ds.id = ds_id;
10539 entry->gs.id = gs_id;
10540 entry->ps.id = ps_id;
10541 entry->cs.id = 0;
10542 entry->constant_version = 0;
10543 entry->shader_controlled_clip_distances = 0;
10544 /* Add the hash table entry */
10546
10547 /* Set the current program */
10548 ctx_data->glsl_program = entry;
10549
10550 /* Attach GLSL vshader */
10551 if (vs_id)
10552 {
10553 TRACE("Attaching GLSL shader object %u to program %u.\n", vs_id, program_id);
10554 GL_EXTCALL(glAttachShader(program_id, vs_id));
10555 checkGLcall("glAttachShader");
10556
10557 list_add_head(vs_list, &entry->vs.shader_entry);
10558 }
10559
10560 if (vshader)
10561 {
10562 attribs_map = vshader->reg_maps.input_registers;
10563 if (vshader->reg_maps.shader_version.major < 4)
10564 {
10565 reorder_shader_id = shader_glsl_generate_vs3_rasterizer_input_setup(priv, vshader, pshader,
10566 state->primitive_type == WINED3D_PT_POINTLIST && vshader->reg_maps.point_size,
10567 d3d_info->emulated_flatshading
10568 && state->render_states[WINED3D_RS_SHADEMODE] == WINED3D_SHADE_FLAT, gl_info);
10569 TRACE("Attaching GLSL shader object %u to program %u.\n", reorder_shader_id, program_id);
10570 GL_EXTCALL(glAttachShader(program_id, reorder_shader_id));
10571 checkGLcall("glAttachShader");
10572 /* Flag the reorder function for deletion, it will be freed
10573 * automatically when the program is destroyed. */
10574 GL_EXTCALL(glDeleteShader(reorder_shader_id));
10575 }
10576 }
10577 else
10578 {
10579 attribs_map = (1u << WINED3D_FFP_ATTRIBS_COUNT) - 1;
10580 }
10581
10583 {
10584 /* Bind vertex attributes to a corresponding index number to match
10585 * the same index numbers as ARB_vertex_programs (makes loading
10586 * vertex attributes simpler). With this method, we can use the
10587 * exact same code to load the attributes later for both ARB and
10588 * GLSL shaders.
10589 *
10590 * We have to do this here because we need to know the Program ID
10591 * in order to make the bindings work, and it has to be done prior
10592 * to linking the GLSL program. */
10594 while (attribs_map)
10595 {
10596 i = wined3d_bit_scan(&attribs_map);
10597 string_buffer_sprintf(tmp_name, "vs_in%u", i);
10598 GL_EXTCALL(glBindAttribLocation(program_id, i, tmp_name->buffer));
10599 if (vshader && vshader->reg_maps.shader_version.major >= 4)
10600 {
10601 string_buffer_sprintf(tmp_name, "vs_in_uint%u", i);
10602 GL_EXTCALL(glBindAttribLocation(program_id, i, tmp_name->buffer));
10603 string_buffer_sprintf(tmp_name, "vs_in_int%u", i);
10604 GL_EXTCALL(glBindAttribLocation(program_id, i, tmp_name->buffer));
10605 }
10606 }
10607 checkGLcall("glBindAttribLocation");
10608
10609 if (!use_legacy_fragment_output(gl_info))
10610 {
10611 for (i = 0; i < WINED3D_MAX_RENDER_TARGETS; ++i)
10612 {
10613 string_buffer_sprintf(tmp_name, "color_out%u", i);
10614 if (state->blend_state && state->blend_state->dual_source)
10615 GL_EXTCALL(glBindFragDataLocationIndexed(program_id, 0, i, tmp_name->buffer));
10616 else
10617 GL_EXTCALL(glBindFragDataLocation(program_id, i, tmp_name->buffer));
10618 checkGLcall("glBindFragDataLocation");
10619 }
10620 }
10622 }
10623
10624 if (hshader)
10625 {
10626 TRACE("Attaching GLSL tessellation control shader object %u to program %u.\n", hs_id, program_id);
10627 GL_EXTCALL(glAttachShader(program_id, hs_id));
10628 checkGLcall("glAttachShader");
10629
10630 list_add_head(&hshader->linked_programs, &entry->hs.shader_entry);
10631 }
10632
10633 if (dshader)
10634 {
10635 TRACE("Attaching GLSL tessellation evaluation shader object %u to program %u.\n", ds_id, program_id);
10636 GL_EXTCALL(glAttachShader(program_id, ds_id));
10637 checkGLcall("glAttachShader");
10638
10639 list_add_head(&dshader->linked_programs, &entry->ds.shader_entry);
10640 }
10641
10642 if (gshader)
10643 {
10644 TRACE("Attaching GLSL geometry shader object %u to program %u.\n", gs_id, program_id);
10645 GL_EXTCALL(glAttachShader(program_id, gs_id));
10646 checkGLcall("glAttachShader");
10647
10648 shader_glsl_init_transform_feedback(context_gl, priv, program_id, gshader);
10649
10650 list_add_head(&gshader->linked_programs, &entry->gs.shader_entry);
10651 }
10652
10653 /* Attach GLSL pshader */
10654 if (ps_id)
10655 {
10656 TRACE("Attaching GLSL shader object %u to program %u.\n", ps_id, program_id);
10657 GL_EXTCALL(glAttachShader(program_id, ps_id));
10658 checkGLcall("glAttachShader");
10659
10660 list_add_head(ps_list, &entry->ps.shader_entry);
10661 }
10662
10663 /* Link the program */
10664 TRACE("Linking GLSL shader program %u.\n", program_id);
10665 GL_EXTCALL(glLinkProgram(program_id));
10666 shader_glsl_validate_link(gl_info, program_id);
10667
10668 shader_glsl_init_vs_uniform_locations(gl_info, priv, program_id, &entry->vs,
10669 vshader ? vshader->limits->constant_float : 0);
10670 shader_glsl_init_ds_uniform_locations(gl_info, priv, program_id, &entry->ds);
10671 shader_glsl_init_gs_uniform_locations(gl_info, priv, program_id, &entry->gs);
10672 shader_glsl_init_ps_uniform_locations(gl_info, priv, program_id, &entry->ps,
10673 pshader ? pshader->limits->constant_float : 0);
10674 checkGLcall("find glsl program uniform locations");
10675
10676 pre_rasterization_shader = gshader ? gshader : dshader ? dshader : vshader;
10677 if (pre_rasterization_shader && pre_rasterization_shader->reg_maps.shader_version.major >= 4)
10678 {
10679 unsigned int clip_distance_count = wined3d_popcount(pre_rasterization_shader->reg_maps.clip_distance_mask);
10680 entry->shader_controlled_clip_distances = 1;
10681 entry->clip_distance_mask = wined3d_mask_from_size(clip_distance_count);
10682 }
10683
10684 if (needs_legacy_glsl_syntax(gl_info))
10685 {
10686 if (pshader && pshader->reg_maps.shader_version.major >= 3
10687 && pshader->u.ps.declared_in_count > vec4_varyings(3, gl_info))
10688 {
10689 TRACE("Shader %d needs vertex color clamping disabled.\n", program_id);
10690 entry->vs.vertex_color_clamp = GL_FALSE;
10691 }
10692 else
10693 {
10694 entry->vs.vertex_color_clamp = GL_FIXED_ONLY_ARB;
10695 }
10696 }
10697 else
10698 {
10699 /* With core profile we never change vertex_color_clamp from
10700 * GL_FIXED_ONLY_MODE (which is also the initial value) so we never call
10701 * glClampColorARB(). */
10702 entry->vs.vertex_color_clamp = GL_FIXED_ONLY_ARB;
10703 }
10704
10705 /* Set the shader to allow uniform loading on it */
10706 GL_EXTCALL(glUseProgram(program_id));
10707 checkGLcall("glUseProgram");
10708
10709 entry->constant_update_mask = 0;
10710 if (vshader)
10711 {
10712 entry->constant_update_mask |= WINED3D_SHADER_CONST_VS_F;
10713 if (vshader->reg_maps.integer_constants)
10714 entry->constant_update_mask |= WINED3D_SHADER_CONST_VS_I;
10715 if (vshader->reg_maps.boolean_constants)
10716 entry->constant_update_mask |= WINED3D_SHADER_CONST_VS_B;
10717 if (entry->vs.pos_fixup_location != -1)
10718 entry->constant_update_mask |= WINED3D_SHADER_CONST_POS_FIXUP;
10719 if (entry->vs.base_vertex_id_location != -1)
10720 entry->constant_update_mask |= WINED3D_SHADER_CONST_BASE_VERTEX_ID;
10721
10722 shader_glsl_load_program_resources(context_gl, priv, program_id, vshader);
10723 }
10724 else
10725 {
10726 entry->constant_update_mask |= WINED3D_SHADER_CONST_FFP_MODELVIEW
10728
10729 for (i = 1; i < MAX_VERTEX_BLENDS; ++i)
10730 {
10731 if (entry->vs.modelview_matrix_location[i] != -1)
10732 {
10733 entry->constant_update_mask |= WINED3D_SHADER_CONST_FFP_VERTEXBLEND;
10734 break;
10735 }
10736 }
10737
10738 for (i = 0; i < WINED3D_MAX_FFP_TEXTURES; ++i)
10739 {
10740 if (entry->vs.texture_matrix_location[i] != -1)
10741 {
10742 entry->constant_update_mask |= WINED3D_SHADER_CONST_FFP_TEXMATRIX;
10743 break;
10744 }
10745 }
10746 if (entry->vs.material_ambient_location != -1 || entry->vs.material_diffuse_location != -1
10747 || entry->vs.material_specular_location != -1
10748 || entry->vs.material_emissive_location != -1
10749 || entry->vs.material_shininess_location != -1)
10750 entry->constant_update_mask |= WINED3D_SHADER_CONST_FFP_MATERIAL;
10751 }
10752 if (entry->vs.clip_planes_location != -1)
10753 entry->constant_update_mask |= WINED3D_SHADER_CONST_VS_CLIP_PLANES;
10754 if (entry->vs.pointsize_min_location != -1)
10755 entry->constant_update_mask |= WINED3D_SHADER_CONST_VS_POINTSIZE;
10756
10757 if (hshader)
10758 shader_glsl_load_program_resources(context_gl, priv, program_id, hshader);
10759
10760 if (dshader)
10761 {
10762 if (entry->ds.pos_fixup_location != -1)
10763 entry->constant_update_mask |= WINED3D_SHADER_CONST_POS_FIXUP;
10764
10765 shader_glsl_load_program_resources(context_gl, priv, program_id, dshader);
10766 }
10767
10768 if (gshader)
10769 {
10770 if (entry->gs.pos_fixup_location != -1)
10771 entry->constant_update_mask |= WINED3D_SHADER_CONST_POS_FIXUP;
10772
10773 shader_glsl_load_program_resources(context_gl, priv, program_id, gshader);
10774 }
10775
10776 if (ps_id)
10777 {
10778 if (pshader)
10779 {
10780 entry->constant_update_mask |= WINED3D_SHADER_CONST_PS_F;
10781 if (pshader->reg_maps.integer_constants)
10782 entry->constant_update_mask |= WINED3D_SHADER_CONST_PS_I;
10783 if (pshader->reg_maps.boolean_constants)
10784 entry->constant_update_mask |= WINED3D_SHADER_CONST_PS_B;
10785
10786 shader_glsl_load_program_resources(context_gl, priv, program_id, pshader);
10787 shader_glsl_load_images(gl_info, priv, program_id, &pshader->reg_maps);
10788 }
10789 else
10790 {
10791 entry->constant_update_mask |= WINED3D_SHADER_CONST_FFP_PS;
10792
10793 shader_glsl_load_samplers(&context_gl->c, priv, program_id, NULL);
10794 }
10795
10796 for (i = 0; i < WINED3D_MAX_FFP_TEXTURES; ++i)
10797 {
10798 if (entry->ps.bumpenv_mat_location[i] != -1)
10799 {
10800 entry->constant_update_mask |= WINED3D_SHADER_CONST_PS_BUMP_ENV;
10801 break;
10802 }
10803 }
10804
10805 if (entry->ps.fog_color_location != -1)
10806 entry->constant_update_mask |= WINED3D_SHADER_CONST_PS_FOG;
10807 if (entry->ps.alpha_test_ref_location != -1)
10808 entry->constant_update_mask |= WINED3D_SHADER_CONST_PS_ALPHA_TEST;
10809 if (entry->ps.color_key_location != -1)
10810 entry->constant_update_mask |= WINED3D_SHADER_CONST_FFP_COLOR_KEY;
10811 }
10812}
struct mke2fs_defaults settings[]
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
Definition: list.h:39
void find_ds_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader, struct ds_compile_args *args, const struct wined3d_context *context)
Definition: shader.c:2838
void find_gs_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader, struct gs_compile_args *args, const struct wined3d_context *context)
Definition: shader.c:2858
void find_ps_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader, BOOL position_transformed, struct ps_compile_args *args, const struct wined3d_context *context)
Definition: shader.c:2871
void find_vs_compile_args(const struct wined3d_state *state, const struct wined3d_shader *shader, struct vs_compile_args *args, const struct wined3d_context *context)
Definition: shader.c:2689
void wined3d_ffp_get_fs_settings(const struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info, struct ffp_frag_settings *settings)
Definition: utils.c:6141
void wined3d_ffp_get_vs_settings(const struct wined3d_state *state, const struct wined3d_stream_info *si, const struct wined3d_d3d_info *d3d_info, struct wined3d_ffp_vs_settings *settings)
Definition: utils.c:6444
#define GL_FALSE
Definition: gl.h:173
#define GL_FIXED_ONLY_ARB
Definition: glext.h:1625
static void shader_glsl_load_program_resources(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, GLuint program_id, const struct wined3d_shader *shader)
Definition: glsl_shader.c:997
static struct glsl_ffp_fragment_shader * shader_glsl_find_ffp_fragment_shader(struct shader_glsl_priv *priv, const struct ffp_frag_settings *args, const struct wined3d_context_gl *context_gl)
static void add_glsl_program_entry(struct shader_glsl_priv *priv, struct glsl_shader_prog_link *entry)
Definition: glsl_shader.c:7042
static GLuint find_glsl_geometry_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, struct wined3d_shader *shader, const struct gs_compile_args *args)
Definition: glsl_shader.c:8930
static BOOL shader_glsl_use_explicit_attrib_location(const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:2092
static GLuint find_glsl_vertex_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, struct wined3d_shader *shader, const struct vs_compile_args *args)
Definition: glsl_shader.c:8767
static GLuint find_glsl_domain_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, struct wined3d_shader *shader, const struct ds_compile_args *args)
Definition: glsl_shader.c:8875
static void shader_glsl_init_gs_uniform_locations(const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, struct glsl_gs_program *gs)
static GLuint find_glsl_hull_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, struct wined3d_shader *shader)
Definition: glsl_shader.c:8830
static void shader_glsl_init_ps_uniform_locations(const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, struct glsl_ps_program *ps, unsigned int ps_c_count)
static unsigned int vec4_varyings(DWORD shader_major, const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:2076
static void shader_glsl_load_images(const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, const struct wined3d_shader_reg_maps *reg_maps)
Definition: glsl_shader.c:967
const struct wined3d_fragment_pipe_ops glsl_fragment_pipe
static void shader_glsl_init_ds_uniform_locations(const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, struct glsl_ds_program *ds)
static void shader_glsl_init_vs_uniform_locations(const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, struct glsl_vs_program *vs, unsigned int vs_c_count)
static void shader_glsl_load_samplers(const struct wined3d_context *context, struct shader_glsl_priv *priv, GLuint program_id, const struct wined3d_shader_reg_maps *reg_maps)
Definition: glsl_shader.c:927
static struct glsl_ffp_vertex_shader * shader_glsl_find_ffp_vertex_shader(struct shader_glsl_priv *priv, const struct wined3d_gl_info *gl_info, const struct wined3d_ffp_vs_settings *settings)
const struct wined3d_vertex_pipe_ops glsl_vertex_pipe
static void shader_glsl_init_transform_feedback(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, GLuint program_id, struct wined3d_shader *shader)
Definition: glsl_shader.c:1136
static GLuint find_glsl_fragment_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, struct wined3d_shader *shader, const struct ps_compile_args *args)
Definition: glsl_shader.c:8685
static GLuint shader_glsl_generate_vs3_rasterizer_input_setup(struct shader_glsl_priv *priv, const struct wined3d_shader *vs, const struct wined3d_shader *ps, BOOL per_vertex_point_size, BOOL flatshading, const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:7318
static char * tmp_name
Definition: cache.c:24
struct list linked_programs
Definition: glsl_shader.c:342
struct list linked_programs
Definition: glsl_shader.c:335
struct wined3d_string_buffer_list string_buffers
Definition: glsl_shader.c:131
const struct wined3d_vertex_pipe_ops * vertex_pipe
Definition: glsl_shader.c:138
const struct wined3d_fragment_pipe_ops * fragment_pipe
Definition: glsl_shader.c:139
uint32_t emulated_flatshading
union wined3d_shader::@358 u
struct wined3d_pixel_shader ps
const struct wined3d_shader_limits * limits
struct wined3d_shader_reg_maps reg_maps
struct list linked_programs
@ WINED3D_SHADE_FLAT
Definition: wined3d.h:488
@ WINED3D_RS_SHADEMODE
Definition: wined3d.h:295
static int wined3d_bit_scan(unsigned int *x)
Definition: wined3d.h:2982
#define WINED3D_MAX_RENDER_TARGETS
Definition: wined3d.h:1606
@ WINED3D_SHADER_TYPE_HULL
Definition: wined3d.h:844
#define WINED3D_SHADER_CONST_PS_BUMP_ENV
@ WINED3D_FFP_ATTRIBS_COUNT
#define WINED3D_SHADER_CONST_BASE_VERTEX_ID
#define WINED3D_SHADER_CONST_PS_F
#define WINED3D_SHADER_CONST_FFP_VERTEXBLEND
#define WINED3D_SHADER_CONST_VS_B
#define WINED3D_SHADER_CONST_VS_I
#define WINED3D_SHADER_CONST_PS_I
#define WINED3D_SHADER_CONST_FFP_COLOR_KEY
#define WINED3D_SHADER_CONST_VS_F
#define WINED3D_SHADER_CONST_PS_ALPHA_TEST
#define WINED3D_SHADER_CONST_PS_B
#define WINED3D_SHADER_CONST_FFP_MODELVIEW
#define WINED3D_SHADER_CONST_FFP_PS
#define WINED3D_SHADER_CONST_FFP_LIGHTS
#define WINED3D_SHADER_CONST_FFP_TEXMATRIX
static unsigned int wined3d_popcount(unsigned int x)
#define WINED3D_SHADER_CONST_FFP_MATERIAL

Referenced by shader_glsl_update_graphics_program().

◆ shader_generate_glsl_declarations()

static void shader_generate_glsl_declarations ( const struct wined3d_context_gl *  context_gl,
struct wined3d_string_buffer *  buffer,
const struct wined3d_shader *  shader,
const struct wined3d_shader_reg_maps *  reg_maps,
const struct shader_glsl_ctx_priv *  ctx_priv 
)
static

Generate the variable & register declarations for the GLSL output target

Definition at line 2371 of file glsl_shader.c.

2374{
2375 const struct wined3d_shader_version *version = &reg_maps->shader_version;
2376 const struct vs_compile_args *vs_args = ctx_priv->cur_vs_args;
2377 const struct ps_compile_args *ps_args = ctx_priv->cur_ps_args;
2378 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
2379 const struct wined3d_shader_indexable_temp *idx_temp_reg;
2380 unsigned int uniform_block_base, uniform_block_count;
2381 enum wined3d_shader_resource_type resource_type;
2382 const struct wined3d_shader_lconst *lconst;
2383 const char *prefix;
2384 unsigned int i;
2385 uint32_t map;
2386
2388 shader_addline(buffer, "#pragma optionNV(fastmath off)\n");
2389
2391
2392 /* Prototype the subroutines */
2393 map = reg_maps->labels;
2394 while (map)
2395 {
2397 shader_addline(buffer, "void subroutine%u();\n", i);
2398 }
2399
2401 {
2402 if (version->type == WINED3D_SHADER_TYPE_HULL)
2403 shader_addline(buffer, "out gl_PerVertex { invariant vec4 gl_Position; } gl_out[];\n");
2404 else
2405 shader_addline(buffer, "invariant gl_Position;\n");
2406 }
2407
2408 /* Declare the constants (aka uniforms) */
2409 if (shader->limits->constant_float > 0)
2410 {
2411 unsigned max_constantsF;
2412
2413 /* Unless the shader uses indirect addressing, always declare the
2414 * maximum array size and ignore that we need some uniforms privately.
2415 * E.g. if GL supports 256 uniforms, and we need 2 for the pos fixup
2416 * and immediate values, still declare VC[256]. If the shader needs
2417 * more uniforms than we have it won't work in any case. If it uses
2418 * less, the compiler will figure out which uniforms are really used
2419 * and strip them out. This allows a shader to use c255 on a dx9 card,
2420 * as long as it doesn't also use all the other constants.
2421 *
2422 * If the shader uses indirect addressing the compiler must assume
2423 * that all declared uniforms are used. In this case, declare only the
2424 * amount that we're assured to have.
2425 *
2426 * Thus we run into problems in these two cases:
2427 * 1) The shader really uses more uniforms than supported.
2428 * 2) The shader uses indirect addressing, less constants than
2429 * supported, but uses a constant index > #supported consts. */
2431 {
2432 /* No indirect addressing here. */
2433 max_constantsF = gl_info->limits.glsl_ps_float_constants;
2434 }
2435 else
2436 {
2437 if (reg_maps->usesrelconstF)
2438 {
2439 /* Subtract the other potential uniforms from the max
2440 * available (bools, ints, and 1 row of projection matrix).
2441 * Subtract another uniform for immediate values, which have
2442 * to be loaded via uniform by the driver as well. The shader
2443 * code only uses 0.5, 2.0, 1.0, 128 and -128 in vertex
2444 * shader code, so one vec4 should be enough. (Unfortunately
2445 * the Nvidia driver doesn't store 128 and -128 in one float).
2446 *
2447 * Writing gl_ClipVertex requires one uniform for each
2448 * clipplane as well. */
2449 max_constantsF = gl_info->limits.glsl_vs_float_constants - 3;
2450 if (vs_args->clip_enabled)
2451 max_constantsF -= gl_info->limits.user_clip_distances;
2452 max_constantsF -= wined3d_popcount(reg_maps->integer_constants);
2453 /* Strictly speaking a bool only uses one scalar, but the nvidia(Linux) compiler doesn't pack them properly,
2454 * so each scalar requires a full vec4. We could work around this by packing the booleans ourselves, but
2455 * for now take this into account when calculating the number of available constants
2456 */
2457 max_constantsF -= wined3d_popcount(reg_maps->boolean_constants);
2458 /* Set by driver quirks in directx.c */
2459 max_constantsF -= gl_info->reserved_glsl_constants;
2460
2461 if (max_constantsF < shader->limits->constant_float)
2462 {
2463 static unsigned int once;
2464
2465 if (!once++)
2466 ERR_(winediag)("The hardware does not support enough uniform components to run this shader,"
2467 " it may not render correctly.\n");
2468 else
2469 WARN("The hardware does not support enough uniform components to run this shader.\n");
2470 }
2471 }
2472 else
2473 {
2474 max_constantsF = gl_info->limits.glsl_vs_float_constants;
2475 }
2476 }
2477 max_constantsF = min(shader->limits->constant_float, max_constantsF);
2478 shader_addline(buffer, "uniform vec4 %s_c[%u];\n", prefix, max_constantsF);
2479 }
2480
2481 /* Always declare the full set of constants, the compiler can remove the
2482 * unused ones because d3d doesn't (yet) support indirect int and bool
2483 * constant addressing. This avoids problems if the app uses e.g. i0 and i9. */
2484 if (shader->limits->constant_int > 0 && reg_maps->integer_constants)
2485 shader_addline(buffer, "uniform ivec4 %s_i[%u];\n", prefix, shader->limits->constant_int);
2486
2487 if (shader->limits->constant_bool > 0 && reg_maps->boolean_constants)
2488 shader_addline(buffer, "uniform bool %s_b[%u];\n", prefix, shader->limits->constant_bool);
2489
2490 /* Declare immediate constant buffer */
2491 if (reg_maps->icb)
2492 shader_addline(buffer, "uniform vec4 %s_icb[%u];\n", prefix, reg_maps->icb->vec4_count);
2493
2494 /* Declare constant buffers */
2496 &uniform_block_base, &uniform_block_count);
2497 for (i = 0; i < min(uniform_block_count, WINED3D_MAX_CBS); ++i)
2498 {
2499 if (reg_maps->cb_sizes[i])
2500 {
2501 shader_addline(buffer, "layout(std140");
2503 shader_addline(buffer, ", binding = %u", uniform_block_base + i);
2504 shader_addline(buffer, ") uniform block_%s_cb%u { vec4 %s_cb%u[%u]; };\n",
2505 prefix, i, prefix, i, reg_maps->cb_sizes[i]);
2506 }
2507 }
2508
2509 /* Declare texture samplers */
2510 for (i = 0; i < reg_maps->sampler_map.count; ++i)
2511 {
2513 const char *sampler_type_prefix, *sampler_type;
2514 BOOL shadow_sampler;
2515
2516 entry = &reg_maps->sampler_map.entries[i];
2517
2518 if (entry->resource_idx >= ARRAY_SIZE(reg_maps->resource_info))
2519 {
2520 ERR("Invalid resource index %u.\n", entry->resource_idx);
2521 continue;
2522 }
2523
2524 switch (reg_maps->resource_info[entry->resource_idx].data_type)
2525 {
2526 case WINED3D_DATA_FLOAT:
2527 case WINED3D_DATA_UNORM:
2528 case WINED3D_DATA_SNORM:
2529 sampler_type_prefix = "";
2530 break;
2531
2532 case WINED3D_DATA_INT:
2533 sampler_type_prefix = "i";
2534 break;
2535
2536 case WINED3D_DATA_UINT:
2537 sampler_type_prefix = "u";
2538 break;
2539
2540 default:
2541 sampler_type_prefix = "";
2542 ERR("Unhandled resource data type %#x.\n", reg_maps->resource_info[i].data_type);
2543 break;
2544 }
2545
2546 shadow_sampler = shader_sampler_is_shadow(shader, ps_args, entry->resource_idx, entry->sampler_idx);
2547 resource_type = version->type == WINED3D_SHADER_TYPE_PIXEL
2548 ? pixelshader_get_resource_type(reg_maps, entry->resource_idx, ps_args->tex_types)
2549 : reg_maps->resource_info[entry->resource_idx].type;
2550
2551 switch (resource_type)
2552 {
2554 sampler_type = "samplerBuffer";
2555 break;
2556
2558 if (shadow_sampler)
2559 sampler_type = "sampler1DShadow";
2560 else
2561 sampler_type = "sampler1D";
2562 break;
2563
2565 if (shadow_sampler)
2566 sampler_type = "sampler2DShadow";
2567 else
2568 sampler_type = "sampler2D";
2569 break;
2570
2572 if (shadow_sampler)
2573 FIXME("Unsupported 3D shadow sampler.\n");
2574 sampler_type = "sampler3D";
2575 break;
2576
2578 if (shadow_sampler)
2579 sampler_type = "samplerCubeShadow";
2580 else
2581 sampler_type = "samplerCube";
2582 break;
2583
2585 if (shadow_sampler)
2586 sampler_type = "sampler1DArrayShadow";
2587 else
2588 sampler_type = "sampler1DArray";
2589 break;
2590
2592 if (shadow_sampler)
2593 sampler_type = "sampler2DArrayShadow";
2594 else
2595 sampler_type = "sampler2DArray";
2596 break;
2597
2599 if (shadow_sampler)
2600 sampler_type = "samplerCubeArrayShadow";
2601 else
2602 sampler_type = "samplerCubeArray";
2603 break;
2604
2606 sampler_type = "sampler2DMS";
2607 break;
2608
2610 sampler_type = "sampler2DMSArray";
2611 break;
2612
2613 default:
2614 sampler_type = "unsupported_sampler";
2615 FIXME("Unhandled resource type %#x.\n", resource_type);
2616 break;
2617 }
2618
2621 shader_addline(buffer, "uniform %s%s %s_sampler%u;\n",
2622 sampler_type_prefix, sampler_type, prefix, entry->bind_idx);
2623 }
2624
2625 /* Declare images */
2626 for (i = 0; i < ARRAY_SIZE(reg_maps->uav_resource_info); ++i)
2627 {
2628 const char *image_type_prefix, *image_type, *read_format;
2629
2630 if (!reg_maps->uav_resource_info[i].type)
2631 continue;
2632
2633 switch (reg_maps->uav_resource_info[i].data_type)
2634 {
2635 case WINED3D_DATA_FLOAT:
2636 case WINED3D_DATA_UNORM:
2637 case WINED3D_DATA_SNORM:
2638 image_type_prefix = "";
2639 read_format = "r32f";
2640 break;
2641
2642 case WINED3D_DATA_INT:
2643 image_type_prefix = "i";
2644 read_format = "r32i";
2645 break;
2646
2647 case WINED3D_DATA_UINT:
2648 image_type_prefix = "u";
2649 read_format = "r32ui";
2650 break;
2651
2652 default:
2653 image_type_prefix = "";
2654 read_format = "";
2655 ERR("Unhandled resource data type %#x.\n", reg_maps->uav_resource_info[i].data_type);
2656 break;
2657 }
2658
2659 switch (reg_maps->uav_resource_info[i].type)
2660 {
2662 image_type = "imageBuffer";
2663 break;
2664
2666 image_type = "image1D";
2667 break;
2668
2670 image_type = "image2D";
2671 break;
2672
2674 image_type = "image3D";
2675 break;
2676
2678 image_type = "image1DArray";
2679 break;
2680
2682 image_type = "image2DArray";
2683 break;
2684
2685 default:
2686 image_type = "unsupported_image";
2687 FIXME("Unhandled resource type %#x.\n", reg_maps->uav_resource_info[i].type);
2688 break;
2689 }
2690
2692 shader_addline(buffer, "layout(binding = %u)\n", i);
2693 if (reg_maps->uav_read_mask & (1u << i))
2694 shader_addline(buffer, "layout(%s) uniform %s%s %s_image%u;\n",
2695 read_format, image_type_prefix, image_type, prefix, i);
2696 else
2697 shader_addline(buffer, "writeonly uniform %s%s %s_image%u;\n",
2698 image_type_prefix, image_type, prefix, i);
2699
2700 if (reg_maps->uav_counter_mask & (1u << i))
2701 shader_addline(buffer, "layout(binding = %u) uniform atomic_uint %s_counter%u;\n",
2702 i, prefix, i);
2703 }
2704
2705 /* Declare address variables */
2706 map = reg_maps->address;
2707 while (map)
2708 {
2710 shader_addline(buffer, "ivec4 A%u;\n", i);
2711 }
2712
2713 /* Declare output register temporaries */
2714 if (shader->limits->packed_output)
2715 shader_addline(buffer, "vec4 %s_out[%u];\n", prefix, shader->limits->packed_output);
2716
2717 /* Declare temporary variables */
2718 if (reg_maps->temporary_count)
2719 {
2720 for (i = 0; i < reg_maps->temporary_count; ++i)
2721 shader_addline(buffer, "vec4 R%u;\n", i);
2722 }
2723 else if (version->major < 4)
2724 {
2725 map = reg_maps->temporary;
2726 while (map)
2727 {
2729 shader_addline(buffer, "vec4 R%u;\n", i);
2730 }
2731 }
2732
2733 /* Declare indexable temporary variables */
2735 {
2736 if (idx_temp_reg->component_count != 4)
2737 FIXME("Ignoring component count %u.\n", idx_temp_reg->component_count);
2738 shader_addline(buffer, "vec4 X%u[%u];\n", idx_temp_reg->register_idx, idx_temp_reg->register_size);
2739 }
2740
2741 /* Declare loop registers aLx */
2742 if (version->major < 4)
2743 {
2744 for (i = 0; i < reg_maps->loop_depth; ++i)
2745 {
2746 shader_addline(buffer, "int aL%u;\n", i);
2747 shader_addline(buffer, "int tmpInt%u;\n", i);
2748 }
2749 }
2750
2751 /* Temporary variables for matrix operations */
2752 shader_addline(buffer, "vec4 tmp0;\n");
2753 shader_addline(buffer, "vec4 tmp1;\n");
2754 if (gl_info->supported[ARB_GPU_SHADER5])
2755 shader_addline(buffer, "precise vec4 tmp_precise[2];\n");
2756 else
2757 shader_addline(buffer, "/* precise */ vec4 tmp_precise[2];\n");
2758
2759 if (!shader->load_local_constsF)
2760 {
2761 LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry)
2762 {
2763 shader_addline(buffer, "const vec4 %s_lc%u = ", prefix, lconst->idx);
2764 shader_glsl_append_imm_vec(buffer, (const float *)lconst->value, ARRAY_SIZE(lconst->value), gl_info);
2765 shader_addline(buffer, ";\n");
2766 }
2767 }
2768}
Definition: _map.h:48
enum wined3d_shader_resource_type pixelshader_get_resource_type(const struct wined3d_shader_reg_maps *reg_maps, unsigned int resource_idx, DWORD tex_types)
Definition: shader.c:3153
static void shader_glsl_append_sampler_binding_qualifier(struct wined3d_string_buffer *buffer, const struct wined3d_context *context, const struct wined3d_shader_version *shader_version, unsigned int sampler_idx)
Definition: glsl_shader.c:915
static void shader_glsl_append_imm_vec(struct wined3d_string_buffer *buffer, const float *values, unsigned int size, const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:424
static BOOL shader_glsl_use_layout_binding_qualifier(const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:838
#define ERR_(ch,...)
Definition: debug.h:156
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:236
const struct vs_compile_args * cur_vs_args
Definition: glsl_shader.c:270
unsigned int reserved_glsl_constants
Definition: wined3d_gl.h:345
unsigned int strict_shader_math
UINT cb_sizes[WINED3D_MAX_CBS]
const struct wined3d_shader_immediate_constant_buffer * icb
struct wined3d_shader_sampler_map sampler_map
struct wined3d_shader_resource_info resource_info[MAX_SHADER_RESOURCE_VIEWS]
struct wined3d_shader_resource_info uav_resource_info[MAX_UNORDERED_ACCESS_VIEWS]
unsigned int resource_idx
Character const *const prefix
Definition: tempnam.cpp:195
@ ARB_GPU_SHADER5
Definition: wined3d_gl.h:87
@ WINED3D_DATA_UINT
@ WINED3D_DATA_INT
@ WINED3D_DATA_SNORM
@ WINED3D_DATA_UNORM
@ WINED3D_DATA_FLOAT
#define WINED3D_MAX_CBS
static BOOL shader_sampler_is_shadow(const struct wined3d_shader *shader, const struct ps_compile_args *ps_args, unsigned int resource_idx, unsigned int sampler_idx)
wined3d_shader_resource_type
@ WINED3D_SHADER_RESOURCE_TEXTURE_3D
@ WINED3D_SHADER_RESOURCE_TEXTURE_2D
@ WINED3D_SHADER_RESOURCE_TEXTURE_1DARRAY
@ WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
@ WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY
@ WINED3D_SHADER_RESOURCE_TEXTURE_CUBE
@ WINED3D_SHADER_RESOURCE_TEXTURE_1D

Referenced by shader_glsl_generate_compute_shader(), shader_glsl_generate_domain_shader(), shader_glsl_generate_fragment_shader(), shader_glsl_generate_geometry_shader(), shader_glsl_generate_hull_shader(), and shader_glsl_generate_vertex_shader().

◆ shader_glsl_add_dst_param()

static DWORD shader_glsl_add_dst_param ( const struct wined3d_shader_instruction *  ins,
const struct wined3d_shader_dst_param *  wined3d_dst,
struct glsl_dst_param *  glsl_dst 
)
static

Definition at line 3466 of file glsl_shader.c.

3468{
3469 struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
3471 size_t len;
3472
3473 glsl_dst->mask_str[0] = '\0';
3474
3476 shader_glsl_get_register_name(&wined3d_dst->reg, wined3d_dst->reg.data_type, reg_name, NULL, ins->ctx);
3477 len = min(reg_name->content_size, ARRAY_SIZE(glsl_dst->reg_name) - 1);
3478 memcpy(glsl_dst->reg_name, reg_name->buffer, len);
3479 glsl_dst->reg_name[len] = '\0';
3481
3482 return shader_glsl_get_write_mask(wined3d_dst, glsl_dst->mask_str);
3483}
reg_name
Definition: amd64_sup.c:11
GLenum GLsizei len
Definition: glext.h:6722
static DWORD shader_glsl_get_write_mask(const struct wined3d_shader_dst_param *param, char *write_mask)
Definition: glsl_shader.c:3281
static void shader_glsl_get_register_name(const struct wined3d_shader_register *reg, enum wined3d_data_type data_type, struct wined3d_string_buffer *register_name, BOOL *is_swizzled, const struct wined3d_shader_context *ctx)
Definition: glsl_shader.c:2858
Definition: glsl.c:40
struct wined3d_string_buffer_list * string_buffers
Definition: glsl_shader.c:273
struct wined3d_shader_register reg
const struct wined3d_shader_context * ctx

Referenced by shader_glsl_add_instruction_modifiers(), shader_glsl_append_dst_ext(), shader_glsl_texbem(), shader_glsl_texdepth(), and shader_glsl_texkill().

◆ shader_glsl_add_instruction_modifiers()

static void shader_glsl_add_instruction_modifiers ( const struct wined3d_shader_instruction *  ins)
static

Process GLSL instruction modifiers

Definition at line 3534 of file glsl_shader.c.

3535{
3536 const struct wined3d_shader_dst_param *dst;
3537 struct glsl_dst_param dst_param;
3538 DWORD modifiers;
3539 unsigned int i;
3540
3541 for (i = 0; i < ins->dst_count; ++i)
3542 {
3543 if ((dst = &ins->dst[i])->reg.type == WINED3DSPR_NULL)
3544 continue;
3545
3546 if (ins->flags & WINED3DSI_PRECISE_XYZW)
3547 {
3548 shader_glsl_add_dst_param(ins, dst, &dst_param);
3549 shader_addline(ins->ctx->buffer, "%s%s = tmp_precise[%u]%s;\n",
3550 dst_param.reg_name, dst_param.mask_str, i, dst_param.mask_str);
3551 }
3552
3553 if (!(modifiers = dst->modifiers))
3554 continue;
3555
3556 shader_glsl_add_dst_param(ins, dst, &dst_param);
3557
3558 if (modifiers & WINED3DSPDM_SATURATE)
3559 {
3560 /* _SAT means to clamp the value of the register to between 0 and 1 */
3561 shader_addline(ins->ctx->buffer, "%s%s = clamp(%s%s, 0.0, 1.0);\n", dst_param.reg_name,
3562 dst_param.mask_str, dst_param.reg_name, dst_param.mask_str);
3563 }
3564
3565 if (modifiers & WINED3DSPDM_MSAMPCENTROID)
3566 {
3567 FIXME("_centroid modifier not handled\n");
3568 }
3569
3570 if (modifiers & WINED3DSPDM_PARTIALPRECISION)
3571 {
3572 /* MSDN says this modifier can be safely ignored, so that's what we'll do. */
3573 }
3574 }
3575}
GLenum GLenum dst
Definition: glext.h:6340
static DWORD shader_glsl_add_dst_param(const struct wined3d_shader_instruction *ins, const struct wined3d_shader_dst_param *wined3d_dst, struct glsl_dst_param *glsl_dst)
Definition: glsl_shader.c:3466
const struct wined3d_shader_dst_param * dst
#define WINED3DSI_PRECISE_XYZW
@ WINED3DSPDM_MSAMPCENTROID
@ WINED3DSPDM_PARTIALPRECISION
@ WINED3DSPDM_SATURATE
@ WINED3DSPR_NULL

Referenced by shader_glsl_handle_instruction().

◆ shader_glsl_add_src_param()

static void shader_glsl_add_src_param ( const struct wined3d_shader_instruction *  ins,
const struct wined3d_shader_src_param *  wined3d_src,
DWORD  mask,
struct glsl_src_param *  glsl_src 
)
static

Definition at line 3457 of file glsl_shader.c.

3459{
3460 shader_glsl_add_src_param_ext(ins->ctx, wined3d_src, mask, glsl_src, wined3d_src->reg.data_type);
3461}
GLenum GLint GLuint mask
Definition: glext.h:6028
static void shader_glsl_add_src_param_ext(const struct wined3d_shader_context *ctx, const struct wined3d_shader_src_param *wined3d_src, DWORD mask, struct glsl_src_param *glsl_src, enum wined3d_data_type data_type)
Definition: glsl_shader.c:3405
Definition: glsl.c:35
struct wined3d_shader_register reg

Referenced by shader_glsl_atomic(), shader_glsl_bem(), shader_glsl_binop(), shader_glsl_bitwise_op(), shader_glsl_breakc(), shader_glsl_callnz(), shader_glsl_case(), shader_glsl_cast(), shader_glsl_cnd(), shader_glsl_compare(), shader_glsl_conditional_move(), shader_glsl_cross(), shader_glsl_dot(), shader_glsl_dp2add(), shader_glsl_dst(), shader_glsl_expp(), shader_glsl_float16(), shader_glsl_gather4(), shader_glsl_generate_condition(), shader_glsl_ifc(), shader_glsl_interpolate(), shader_glsl_ld(), shader_glsl_ld_raw_structured(), shader_glsl_ld_uav(), shader_glsl_lit(), shader_glsl_lrp(), shader_glsl_mad(), shader_glsl_map2gl(), shader_glsl_mov(), shader_glsl_mul_extended(), shader_glsl_nrm(), shader_glsl_pow(), shader_glsl_relop(), shader_glsl_rep(), shader_glsl_resinfo(), shader_glsl_sample(), shader_glsl_sample_c(), shader_glsl_scalar_op(), shader_glsl_sgn(), shader_glsl_sincos(), shader_glsl_store_raw_structured(), shader_glsl_store_uav(), shader_glsl_swapc(), shader_glsl_switch(), shader_glsl_tex(), shader_glsl_texbem(), shader_glsl_texcoord(), shader_glsl_texdp3(), shader_glsl_texdp3tex(), shader_glsl_texldd(), shader_glsl_texldl(), shader_glsl_texm3x2depth(), shader_glsl_texm3x2pad(), shader_glsl_texm3x2tex(), shader_glsl_texm3x3(), shader_glsl_texm3x3pad(), shader_glsl_texm3x3spec(), shader_glsl_texm3x3tex(), shader_glsl_texm3x3vspec(), shader_glsl_texreg2rgb(), shader_glsl_to_int(), shader_glsl_to_uint(), shader_glsl_udiv(), and shader_glsl_unary_op().

◆ shader_glsl_add_src_param_ext()

static void shader_glsl_add_src_param_ext ( const struct wined3d_shader_context *  ctx,
const struct wined3d_shader_src_param *  wined3d_src,
DWORD  mask,
struct glsl_src_param *  glsl_src,
enum wined3d_data_type  data_type 
)
static

Definition at line 3405 of file glsl_shader.c.

3408{
3409 struct shader_glsl_ctx_priv *priv = ctx->backend_data;
3410 struct wined3d_string_buffer *param_str = string_buffer_get(priv->string_buffers);
3412 enum wined3d_data_type param_data_type;
3413 BOOL is_color = FALSE;
3414 char swizzle_str[6];
3415 unsigned int size;
3416
3417 glsl_src->param_str[0] = '\0';
3418 swizzle_str[0] = '\0';
3419
3420 shader_glsl_get_register_name(&wined3d_src->reg, data_type, reg_name, &is_color, ctx);
3421 shader_glsl_get_swizzle(wined3d_src, is_color, mask, swizzle_str);
3422
3423 switch (wined3d_src->reg.type)
3424 {
3426 param_data_type = data_type;
3427 size = wined3d_src->reg.immconst_type == WINED3D_IMMCONST_SCALAR ? 1 : 4;
3428 break;
3434 case WINED3DSPR_PRIMID:
3435 param_data_type = WINED3D_DATA_INT;
3436 size = 1;
3437 break;
3441 param_data_type = WINED3D_DATA_INT;
3442 size = 3;
3443 break;
3444 default:
3445 param_data_type = WINED3D_DATA_FLOAT;
3446 size = 4;
3447 break;
3448 }
3449
3450 shader_glsl_sprintf_cast(param_str, reg_name->buffer, data_type, param_data_type, size);
3451 shader_glsl_gen_modifier(wined3d_src->modifiers, param_str->buffer, swizzle_str, glsl_src->param_str);
3452
3454 string_buffer_release(priv->string_buffers, param_str);
3455}
static void shader_glsl_gen_modifier(enum wined3d_shader_src_modifier src_modifier, const char *in_reg, const char *in_regswizzle, char *out_str)
Definition: glsl_shader.c:2796
enum wined3d_data_type data_type
Definition: glsl_shader.c:71
static void shader_glsl_sprintf_cast(struct wined3d_string_buffer *dst_param, const char *src_param, enum wined3d_data_type dst_data_type, enum wined3d_data_type src_data_type, unsigned int size)
Definition: glsl_shader.c:3343
static void shader_glsl_get_swizzle(const struct wined3d_shader_src_param *param, BOOL fixup, DWORD mask, char *swizzle_str)
Definition: glsl_shader.c:3334
enum wined3d_shader_src_modifier modifiers
wined3d_data_type
@ WINED3DSPR_PRIMID
@ WINED3DSPR_LOCALTHREADID
@ WINED3DSPR_IMMCONST
@ WINED3DSPR_OUTPOINTID
@ WINED3DSPR_GSINSTID
@ WINED3DSPR_THREADGROUPID
@ WINED3DSPR_JOININSTID
@ WINED3DSPR_THREADID
@ WINED3DSPR_LOCALTHREADINDEX
@ WINED3DSPR_FORKINSTID
@ WINED3D_IMMCONST_SCALAR

Referenced by shader_glsl_add_src_param(), shader_glsl_atomic(), shader_glsl_get_register_name(), and shader_glsl_store_uav().

◆ shader_glsl_add_version_declaration()

◆ shader_glsl_alloc()

static HRESULT shader_glsl_alloc ( struct wined3d_device *  device,
const struct wined3d_vertex_pipe_ops *  vertex_pipe,
const struct wined3d_fragment_pipe_ops *  fragment_pipe 
)
static

Definition at line 11215 of file glsl_shader.c.

11217{
11219 void *vertex_priv, *fragment_priv;
11220 struct shader_glsl_priv *priv;
11221
11222 if (!(priv = calloc(1, sizeof(*priv))))
11223 return E_OUTOFMEMORY;
11224
11226 {
11227 TRACE("Using %s.\n", vkd3d_shader_get_version(NULL, NULL));
11228 priv->use_vkd3d = true;
11229 }
11230
11232
11233 if (!(vertex_priv = vertex_pipe->vp_alloc(&glsl_shader_backend, priv)))
11234 {
11235 ERR("Failed to initialize vertex pipe.\n");
11236 free(priv);
11237 return E_FAIL;
11238 }
11239
11240 if (!(fragment_priv = fragment_pipe->alloc_private(&glsl_shader_backend, priv)))
11241 {
11242 ERR("Failed to initialize fragment pipe.\n");
11243 vertex_pipe->vp_free(device, NULL);
11244 free(priv);
11245 return E_FAIL;
11246 }
11247
11248 if (!string_buffer_init(&priv->shader_buffer))
11249 {
11250 ERR("Failed to initialize shader buffer.\n");
11251 goto fail;
11252 }
11253
11254 if (!(priv->stack = calloc(stack_size, sizeof(*priv->stack))))
11255 {
11256 ERR("Failed to allocate memory.\n");
11257 goto fail;
11258 }
11259
11261 {
11262 ERR("Failed to initialize vertex shader constant heap\n");
11263 goto fail;
11264 }
11265
11267 {
11268 ERR("Failed to initialize pixel shader constant heap\n");
11269 goto fail;
11270 }
11271
11273
11274 priv->next_constant_version = 1;
11275 priv->vertex_pipe = vertex_pipe;
11277 priv->legacy_lighting = device->wined3d->flags & WINED3D_LEGACY_FFP_LIGHTING;
11278
11279 device->vertex_priv = vertex_priv;
11280 device->fragment_priv = fragment_priv;
11281 device->shader_priv = priv;
11282
11283 return WINED3D_OK;
11284
11285fail:
11286 constant_free(&priv->pconst_heap);
11287 constant_free(&priv->vconst_heap);
11288 free(priv->stack);
11290 fragment_pipe->free_private(device, NULL);
11291 vertex_pipe->vp_free(device, NULL);
11292 free(priv);
11293 return E_OUTOFMEMORY;
11294}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
BOOL string_buffer_init(struct wined3d_string_buffer *buffer)
Definition: shader.c:417
void string_buffer_list_init(struct wined3d_string_buffer_list *list)
Definition: shader.c:539
static const size_t stack_size
Definition: engine.c:61
static BOOL constant_heap_init(struct constant_heap *heap, unsigned int constant_count)
static int glsl_program_key_compare(const void *key, const struct wine_rb_entry *entry)
static void constant_free(struct constant_heap *heap)
struct constant_heap pconst_heap
Definition: glsl_shader.c:134
unsigned char * stack
Definition: glsl_shader.c:135
UINT next_constant_version
Definition: glsl_shader.c:136
struct constant_heap vconst_heap
Definition: glsl_shader.c:133
enum wined3d_shader_backend shader_backend
VKD3D_SHADER_API const char * vkd3d_shader_get_version(unsigned int *major, unsigned int *minor)
static unsigned int wined3d_log2i(unsigned int x)
Definition: wined3d.h:2952
#define WINED3D_OK
Definition: wined3d.h:33
#define WINED3D_MAX_PS_CONSTS_F
Definition: wined3d.h:1605
#define WINED3D_MAX_VS_CONSTS_F
Definition: wined3d.h:1604
#define WINED3D_LEGACY_FFP_LIGHTING
Definition: wined3d.h:1329
@ WINED3D_SHADER_BACKEND_GLSL_VKD3D

◆ shader_glsl_allocate_context_data()

static BOOL shader_glsl_allocate_context_data ( struct wined3d_context *  context)
static

Definition at line 11314 of file glsl_shader.c.

11315{
11316 struct glsl_context_data *ctx_data;
11317
11318 if (!(ctx_data = calloc(1, sizeof(*ctx_data))))
11319 return FALSE;
11321 context->shader_backend_data = ctx_data;
11322 return TRUE;
11323}
GLenum vertex_color_clamp
Definition: glsl_shader.c:279

◆ shader_glsl_append_dst()

◆ shader_glsl_append_dst_ext()

static DWORD shader_glsl_append_dst_ext ( struct wined3d_string_buffer *  buffer,
const struct wined3d_shader_instruction *  ins,
const struct wined3d_shader_dst_param *  dst,
unsigned int  dst_idx,
enum wined3d_data_type  data_type 
)
static

Definition at line 3486 of file glsl_shader.c.

3489{
3490 struct glsl_dst_param glsl_dst;
3491 DWORD mask;
3492
3494 {
3495 if (ins->flags & WINED3DSI_PRECISE_XYZW)
3496 sprintf(glsl_dst.reg_name, "tmp_precise[%u]", dst_idx);
3497
3498 switch (data_type)
3499 {
3500 case WINED3D_DATA_FLOAT:
3501 case WINED3D_DATA_UNORM:
3502 case WINED3D_DATA_SNORM:
3503 shader_addline(buffer, "%s%s = %s(",
3504 glsl_dst.reg_name, glsl_dst.mask_str, shift_glsl_tab[dst->shift]);
3505 break;
3506 case WINED3D_DATA_INT:
3507 shader_addline(buffer, "%s%s = %sintBitsToFloat(",
3508 glsl_dst.reg_name, glsl_dst.mask_str, shift_glsl_tab[dst->shift]);
3509 break;
3512 case WINED3D_DATA_UINT:
3513 shader_addline(buffer, "%s%s = %suintBitsToFloat(",
3514 glsl_dst.reg_name, glsl_dst.mask_str, shift_glsl_tab[dst->shift]);
3515 break;
3516 default:
3517 FIXME("Unhandled data type %#x.\n", data_type);
3518 shader_addline(buffer, "%s%s = %s(",
3519 glsl_dst.reg_name, glsl_dst.mask_str, shift_glsl_tab[dst->shift]);
3520 break;
3521 }
3522 }
3523
3524 return mask;
3525}
static const char *const shift_glsl_tab[]
Definition: glsl_shader.c:2776
#define sprintf
Definition: sprintf.c:45
@ WINED3D_DATA_SAMPLER
@ WINED3D_DATA_RESOURCE

Referenced by PRINTF_ATTR(), shader_glsl_append_dst(), shader_glsl_atomic(), shader_glsl_bitwise_op(), shader_glsl_conditional_move(), shader_glsl_float16(), shader_glsl_gather4(), shader_glsl_gen_sample_c_lz_emulation(), shader_glsl_ld_raw_structured(), shader_glsl_ld_uav(), shader_glsl_mul_extended(), shader_glsl_resinfo(), shader_glsl_sample_info(), shader_glsl_sincos(), shader_glsl_swapc(), and shader_glsl_udiv().

◆ shader_glsl_append_fixup_arg()

static void shader_glsl_append_fixup_arg ( char *  arguments,
const char *  reg_name,
BOOL  sign_fixup,
enum fixup_channel_source  channel_source 
)
static

Definition at line 3689 of file glsl_shader.c.

3691{
3692 switch(channel_source)
3693 {
3695 strcat(arguments, "0.0");
3696 break;
3697
3698 case CHANNEL_SOURCE_ONE:
3699 strcat(arguments, "1.0");
3700 break;
3701
3702 case CHANNEL_SOURCE_X:
3703 strcat(arguments, reg_name);
3704 strcat(arguments, ".x");
3705 break;
3706
3707 case CHANNEL_SOURCE_Y:
3708 strcat(arguments, reg_name);
3709 strcat(arguments, ".y");
3710 break;
3711
3712 case CHANNEL_SOURCE_Z:
3713 strcat(arguments, reg_name);
3714 strcat(arguments, ".z");
3715 break;
3716
3717 case CHANNEL_SOURCE_W:
3718 strcat(arguments, reg_name);
3719 strcat(arguments, ".w");
3720 break;
3721
3722 default:
3723 FIXME("Unhandled channel source %#x\n", channel_source);
3724 strcat(arguments, "undefined");
3725 break;
3726 }
3727
3728 if (sign_fixup) strcat(arguments, " * 2.0 - 1.0");
3729}
strcat
Definition: string.h:92
@ CHANNEL_SOURCE_ONE
@ CHANNEL_SOURCE_W
@ CHANNEL_SOURCE_X
@ CHANNEL_SOURCE_ZERO
@ CHANNEL_SOURCE_Z
@ CHANNEL_SOURCE_Y

Referenced by shader_glsl_color_correction_ext().

◆ shader_glsl_append_imm_ivec()

static void shader_glsl_append_imm_ivec ( struct wined3d_string_buffer *  buffer,
const int *  values,
unsigned int  size 
)
static

Definition at line 463 of file glsl_shader.c.

465{
466 int i;
467
468 if (!size || size > 4)
469 {
470 ERR("Invalid vector size %u.\n", size);
471 return;
472 }
473
474 if (size > 1)
475 shader_addline(buffer, "ivec%u(", size);
476
477 for (i = 0; i < size; ++i)
478 shader_addline(buffer, i ? ", %#x" : "%#x", values[i]);
479
480 if (size > 1)
482}
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:5666

Referenced by PRINTF_ATTR(), shader_glsl_gather4(), and shader_glsl_gen_sample_c_lz_emulation().

◆ shader_glsl_append_imm_vec()

static void shader_glsl_append_imm_vec ( struct wined3d_string_buffer *  buffer,
const float *  values,
unsigned int  size,
const struct wined3d_gl_info *  gl_info 
)
static

Definition at line 424 of file glsl_shader.c.

426{
427 const int *int_values = (const int *)values;
428 unsigned int i;
429 char str[17];
430
431 if (!gl_info->supported[ARB_SHADER_BIT_ENCODING])
432 {
433 if (size > 1)
434 shader_addline(buffer, "vec%u(", size);
435
436 for (i = 0; i < size; ++i)
437 {
439 shader_addline(buffer, i ? ", %s" : "%s", str);
440 }
441
442 if (size > 1)
444
445 return;
446 }
447
448 shader_addline(buffer, "intBitsToFloat(");
449 if (size > 1)
450 shader_addline(buffer, "ivec%u(", size);
451
452 for (i = 0; i < size; ++i)
453 {
455 shader_addline(buffer, i ? ", %#x /* %s */" : "%#x /* %s */", int_values[i], str);
456 }
457
458 if (size > 1)
461}
void wined3d_ftoa(float value, char *s)
Definition: utils.c:6643
const WCHAR * str
@ ARB_SHADER_BIT_ENCODING
Definition: wined3d_gl.h:110

Referenced by shader_generate_glsl_declarations(), shader_glsl_generate_ffp_fragment_shader(), shader_glsl_generate_fragment_shader(), and shader_glsl_get_register_name().

◆ shader_glsl_append_sampler_binding_qualifier()

static void shader_glsl_append_sampler_binding_qualifier ( struct wined3d_string_buffer *  buffer,
const struct wined3d_context *  context,
const struct wined3d_shader_version *  shader_version,
unsigned int  sampler_idx 
)
static

Definition at line 915 of file glsl_shader.c.

918{
919 unsigned int mapped_unit = shader_glsl_map_tex_unit(context, shader_version, sampler_idx);
920 if (mapped_unit != WINED3D_UNMAPPED_STAGE)
921 shader_addline(buffer, "layout(binding = %u)\n", mapped_unit);
922 else
923 ERR("Unmapped sampler %u.\n", sampler_idx);
924}
static unsigned int shader_glsl_map_tex_unit(const struct wined3d_context *context, const struct wined3d_shader_version *shader_version, unsigned int sampler_idx)
Definition: glsl_shader.c:900
#define WINED3D_UNMAPPED_STAGE

Referenced by shader_generate_glsl_declarations(), and shader_glsl_generate_ffp_fragment_shader().

◆ shader_glsl_apply_compute_state()

static void shader_glsl_apply_compute_state ( void *  shader_priv,
struct wined3d_context *  context,
const struct wined3d_state *  state 
)
static

Definition at line 10928 of file glsl_shader.c.

10930{
10931 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
10932 struct shader_glsl_priv *priv = shader_priv;
10933
10934 if (context_gl->c.shader_update_mask & (1u << WINED3D_SHADER_TYPE_COMPUTE))
10935 shader_glsl_update_compute_program(priv, context_gl, state);
10936}
static void shader_glsl_update_compute_program(struct shader_glsl_priv *priv, struct wined3d_context_gl *context_gl, const struct wined3d_state *state)

◆ shader_glsl_apply_draw_state()

static void shader_glsl_apply_draw_state ( void *  shader_priv,
struct wined3d_context *  context,
const struct wined3d_state *  state 
)
static

Definition at line 10887 of file glsl_shader.c.

10889{
10890 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
10891 struct shader_glsl_priv *priv = shader_priv;
10892
10894
10895 if (context->shader_update_mask & ~(1u << WINED3D_SHADER_TYPE_COMPUTE))
10896 shader_glsl_update_graphics_program(priv, context_gl, state);
10897
10898 if (context->constant_update_mask)
10900}
static void shader_glsl_update_graphics_program(struct shader_glsl_priv *priv, struct wined3d_context_gl *context_gl, const struct wined3d_state *state)
static void shader_glsl_update_legacy_states(struct wined3d_context_gl *context_gl, const struct wined3d_state *state)
static void shader_glsl_load_constants(struct shader_glsl_priv *priv, struct wined3d_context *context, const struct wined3d_state *state)
Definition: glsl_shader.c:1716

◆ shader_glsl_atomic()

static void shader_glsl_atomic ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5517 of file glsl_shader.c.

5518{
5519 const BOOL is_imm_instruction = WINED3DSIH_IMM_ATOMIC_AND <= ins->handler_idx
5521 const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps;
5522 const struct wined3d_shader_version *version = &reg_maps->shader_version;
5523 struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
5524 struct glsl_src_param structure_idx, offset, data, data2;
5525 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
5526 enum wined3d_shader_resource_type resource_type;
5529 unsigned int resource_idx, stride;
5530 const char *op, *resource;
5531 DWORD coord_mask;
5532 BOOL is_tgsm;
5533
5534 resource_idx = ins->dst[is_imm_instruction].reg.idx[0].offset;
5535 is_tgsm = ins->dst[is_imm_instruction].reg.type == WINED3DSPR_GROUPSHAREDMEM;
5536 if (is_tgsm)
5537 {
5538 if (resource_idx >= reg_maps->tgsm_count)
5539 {
5540 ERR("Invalid TGSM index %u.\n", resource_idx);
5541 return;
5542 }
5543 resource = "g";
5545 coord_mask = 1;
5546 stride = reg_maps->tgsm[resource_idx].stride;
5547 }
5548 else
5549 {
5550 if (resource_idx >= ARRAY_SIZE(reg_maps->uav_resource_info))
5551 {
5552 ERR("Invalid UAV index %u.\n", resource_idx);
5553 return;
5554 }
5555 resource_type = reg_maps->uav_resource_info[resource_idx].type;
5556 if (resource_type >= ARRAY_SIZE(resource_type_info))
5557 {
5558 ERR("Unexpected resource type %#x.\n", resource_type);
5559 return;
5560 }
5561 resource = "image";
5562 data_type = reg_maps->uav_resource_info[resource_idx].data_type;
5563 coord_mask = wined3d_mask_from_size(resource_type_info[resource_type].coord_size);
5564 stride = reg_maps->uav_resource_info[resource_idx].stride;
5565 }
5566
5567 switch (ins->handler_idx)
5568 {
5571 if (is_tgsm)
5572 op = "atomicAnd";
5573 else
5574 op = "imageAtomicAnd";
5575 break;
5578 if (is_tgsm)
5579 op = "atomicCompSwap";
5580 else
5581 op = "imageAtomicCompSwap";
5582 break;
5585 if (is_tgsm)
5586 op = "atomicAdd";
5587 else
5588 op = "imageAtomicAdd";
5589 break;
5592 if (is_tgsm)
5593 op = "atomicMax";
5594 else
5595 op = "imageAtomicMax";
5597 {
5598 FIXME("Unhandled opcode %#x for unsigned integers.\n", ins->handler_idx);
5599 return;
5600 }
5601 break;
5604 if (is_tgsm)
5605 op = "atomicMin";
5606 else
5607 op = "imageAtomicMin";
5609 {
5610 FIXME("Unhandled opcode %#x for unsigned integers.\n", ins->handler_idx);
5611 return;
5612 }
5613 break;
5616 if (is_tgsm)
5617 op = "atomicOr";
5618 else
5619 op = "imageAtomicOr";
5620 break;
5623 if (is_tgsm)
5624 op = "atomicMax";
5625 else
5626 op = "imageAtomicMax";
5628 {
5629 FIXME("Unhandled opcode %#x for signed integers.\n", ins->handler_idx);
5630 return;
5631 }
5632 break;
5635 if (is_tgsm)
5636 op = "atomicMin";
5637 else
5638 op = "imageAtomicMin";
5640 {
5641 FIXME("Unhandled opcode %#x for signed integers.\n", ins->handler_idx);
5642 return;
5643 }
5644 break;
5647 if (is_tgsm)
5648 op = "atomicXor";
5649 else
5650 op = "imageAtomicXor";
5651 break;
5653 if (is_tgsm)
5654 op = "atomicExchange";
5655 else
5656 op = "imageAtomicExchange";
5657 break;
5658 default:
5659 ERR("Unhandled opcode %#x.\n", ins->handler_idx);
5660 return;
5661 }
5662
5664 if (stride)
5665 {
5666 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &structure_idx);
5668 string_buffer_sprintf(address, "%s * %u + %s / 4", structure_idx.param_str, stride, offset.param_str);
5669 }
5670 else
5671 {
5672 shader_glsl_add_src_param(ins, &ins->src[0], coord_mask, &offset);
5673 string_buffer_sprintf(address, "%s", offset.param_str);
5674 if (is_tgsm || (reg_maps->uav_resource_info[resource_idx].flags & WINED3D_VIEW_BUFFER_RAW))
5675 shader_addline(address, "/ 4");
5676 }
5677
5678 if (is_imm_instruction)
5679 shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &ins->dst[0], 0, data_type);
5680
5681 if (is_tgsm)
5682 shader_addline(buffer, "%s(%s_%s%u[%s], ",
5683 op, shader_glsl_get_prefix(version->type), resource, resource_idx, address->buffer);
5684 else
5685 shader_addline(buffer, "%s(%s_%s%u, %s, ",
5686 op, shader_glsl_get_prefix(version->type), resource, resource_idx, address->buffer);
5687
5689 shader_addline(buffer, "%s", data.param_str);
5690 if (ins->src_count >= 3)
5691 {
5693 shader_addline(buffer, ", %s", data2.param_str);
5694 }
5695
5696 if (is_imm_instruction)
5697 shader_addline(buffer, ")");
5698 shader_addline(buffer, ");\n");
5699
5701}
GLsizei stride
Definition: glext.h:5848
GLuint address
Definition: glext.h:9393
unsigned int coord_size
Definition: glsl_shader.c:50
static void shader_glsl_add_src_param(const struct wined3d_shader_instruction *ins, const struct wined3d_shader_src_param *wined3d_src, DWORD mask, struct glsl_src_param *glsl_src)
Definition: glsl_shader.c:3457
static const struct @335 resource_type_info[]
#define resource
Definition: kernel32.h:9
Definition: tftpd.h:138
const struct wined3d_shader_src_param * src
enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx
struct wined3d_shader_tgsm * tgsm
#define WINED3D_VIEW_BUFFER_RAW
Definition: wined3d.h:1579
#define WINED3DSP_WRITEMASK_0
@ WINED3DSIH_ATOMIC_XOR
@ WINED3DSIH_IMM_ATOMIC_XOR
@ WINED3DSIH_IMM_ATOMIC_IADD
@ WINED3DSIH_IMM_ATOMIC_UMAX
@ WINED3DSIH_ATOMIC_IMAX
@ WINED3DSIH_ATOMIC_AND
@ WINED3DSIH_ATOMIC_UMIN
@ WINED3DSIH_ATOMIC_OR
@ WINED3DSIH_ATOMIC_CMP_STORE
@ WINED3DSIH_ATOMIC_IADD
@ WINED3DSIH_IMM_ATOMIC_AND
@ WINED3DSIH_IMM_ATOMIC_UMIN
@ WINED3DSIH_IMM_ATOMIC_CMP_EXCH
@ WINED3DSIH_ATOMIC_IMIN
@ WINED3DSIH_IMM_ATOMIC_IMAX
@ WINED3DSIH_IMM_ATOMIC_IMIN
@ WINED3DSIH_IMM_ATOMIC_EXCH
@ WINED3DSIH_IMM_ATOMIC_OR
@ WINED3DSIH_ATOMIC_UMAX
@ WINED3DSPR_GROUPSHAREDMEM
#define WINED3DSP_WRITEMASK_1

◆ shader_glsl_bem()

static void shader_glsl_bem ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 6812 of file glsl_shader.c.

6813{
6814 unsigned int sampler_idx = ins->dst[0].reg.idx[0].offset;
6815 struct glsl_src_param src0_param, src1_param;
6816
6819
6820 shader_glsl_append_dst(ins->ctx->buffer, ins);
6821 shader_addline(ins->ctx->buffer, "%s + bumpenv_mat%u * %s);\n",
6822 src0_param.param_str, sampler_idx, src1_param.param_str);
6823}
static DWORD shader_glsl_append_dst(struct wined3d_string_buffer *buffer, const struct wined3d_shader_instruction *ins)
Definition: glsl_shader.c:3528

◆ shader_glsl_binop()

static void shader_glsl_binop ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 3895 of file glsl_shader.c.

3896{
3897 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
3898 struct glsl_src_param src0_param;
3899 struct glsl_src_param src1_param;
3900 DWORD write_mask;
3901 const char *op;
3902
3903 /* Determine the GLSL operator to use based on the opcode */
3904 switch (ins->handler_idx)
3905 {
3906 case WINED3DSIH_ADD: op = "+"; break;
3907 case WINED3DSIH_AND: op = "&"; break;
3908 case WINED3DSIH_DIV: op = "/"; break;
3909 case WINED3DSIH_IADD: op = "+"; break;
3910 case WINED3DSIH_ISHL: op = "<<"; break;
3911 case WINED3DSIH_ISHR: op = ">>"; break;
3912 case WINED3DSIH_MUL: op = "*"; break;
3913 case WINED3DSIH_OR: op = "|"; break;
3914 case WINED3DSIH_SUB: op = "-"; break;
3915 case WINED3DSIH_USHR: op = ">>"; break;
3916 case WINED3DSIH_XOR: op = "^"; break;
3917 default:
3918 op = "<unhandled operator>";
3919 FIXME("Opcode %s not yet handled in GLSL.\n", debug_d3dshaderinstructionhandler(ins->handler_idx));
3920 break;
3921 }
3922
3923 write_mask = shader_glsl_append_dst(buffer, ins);
3924 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
3925 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
3926 shader_addline(buffer, "%s %s %s);\n", src0_param.param_str, op, src1_param.param_str);
3927}
const char * debug_d3dshaderinstructionhandler(enum WINED3D_SHADER_INSTRUCTION_HANDLER handler_idx)
Definition: shader.c:301
@ WINED3DSIH_MUL
@ WINED3DSIH_IADD
@ WINED3DSIH_ISHL
@ WINED3DSIH_SUB
@ WINED3DSIH_OR
@ WINED3DSIH_AND
@ WINED3DSIH_ADD
@ WINED3DSIH_XOR
@ WINED3DSIH_USHR
@ WINED3DSIH_DIV
@ WINED3DSIH_ISHR

◆ shader_glsl_bitwise_op()

static void shader_glsl_bitwise_op ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4304 of file glsl_shader.c.

4305{
4306 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4308 struct glsl_src_param src[4];
4309 const char *instruction;
4310 BOOL tmp_dst = FALSE;
4311 char mask_char[6];
4312 unsigned int i, j;
4313 DWORD write_mask;
4314
4315 switch (ins->handler_idx)
4316 {
4317 case WINED3DSIH_BFI: instruction = "bitfieldInsert"; break;
4318 case WINED3DSIH_IBFE: instruction = "bitfieldExtract"; break;
4319 case WINED3DSIH_UBFE: instruction = "bitfieldExtract"; break;
4320 default:
4321 ERR("Unhandled opcode %#x.\n", ins->handler_idx);
4322 return;
4323 }
4324
4325 for (i = 0; i < ins->src_count; ++i)
4326 {
4327 if (ins->dst[0].reg.idx[0].offset == ins->src[i].reg.idx[0].offset
4328 && ins->dst[0].reg.type == ins->src[i].reg.type)
4329 tmp_dst = TRUE;
4330 }
4331
4332 dst = ins->dst[0];
4333 for (i = 0; i < 4; ++i)
4334 {
4335 dst.write_mask = ins->dst[0].write_mask & (WINED3DSP_WRITEMASK_0 << i);
4336 if (tmp_dst && (write_mask = shader_glsl_get_write_mask(&dst, mask_char)))
4337 shader_addline(buffer, "tmp0%s = %sBitsToFloat(", mask_char,
4338 dst.reg.data_type == WINED3D_DATA_INT ? "int" : "uint");
4339 else if (!(write_mask = shader_glsl_append_dst_ext(buffer, ins, &dst, 0, dst.reg.data_type)))
4340 continue;
4341
4342 for (j = 0; j < ins->src_count; ++j)
4343 shader_glsl_add_src_param(ins, &ins->src[j], write_mask, &src[j]);
4345 for (j = 0; j < ins->src_count - 2; ++j)
4346 shader_addline(buffer, "%s, ", src[ins->src_count - j - 1].param_str);
4347 shader_addline(buffer, "%s & 0x1f, %s & 0x1f));\n", src[1].param_str, src[0].param_str);
4348 }
4349
4350 if (tmp_dst)
4351 {
4353 shader_glsl_get_write_mask(&ins->dst[0], mask_char);
4354 shader_addline(buffer, "tmp0%s);\n", mask_char);
4355 }
4356}
GLenum src
Definition: glext.h:6340
char param_str[200]
Definition: glsl_shader.c:91
@ WINED3DSIH_UBFE
@ WINED3DSIH_BFI
@ WINED3DSIH_IBFE

◆ shader_glsl_break()

static void shader_glsl_break ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5248 of file glsl_shader.c.

5249{
5250 shader_addline(ins->ctx->buffer, "break;\n");
5251}

◆ shader_glsl_breakc()

static void shader_glsl_breakc ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5254 of file glsl_shader.c.

5255{
5256 struct glsl_src_param src0_param;
5257 struct glsl_src_param src1_param;
5258
5259 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
5260 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0, &src1_param);
5261
5262 shader_addline(ins->ctx->buffer, "if (%s %s %s) break;\n",
5263 src0_param.param_str, shader_glsl_get_rel_op(ins->flags), src1_param.param_str);
5264}
static const char * shader_glsl_get_rel_op(enum wined3d_shader_rel_op op)
Definition: glsl_shader.c:3577

◆ shader_glsl_bufinfo()

static void shader_glsl_bufinfo ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5987 of file glsl_shader.c.

5988{
5989 const char *prefix = shader_glsl_get_prefix(ins->ctx->reg_maps->shader_version.type);
5990 const struct wined3d_shader_resource_info *resource_info;
5991 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
5992 unsigned int resource_idx;
5993 char dst_swizzle[6];
5994 DWORD write_mask;
5995
5996 write_mask = shader_glsl_append_dst(buffer, ins);
5997 shader_glsl_get_swizzle(&ins->src[0], FALSE, write_mask, dst_swizzle);
5998
5999 if (!(resource_info = shader_glsl_get_resource_info(ins, &ins->src[0].reg)))
6000 return;
6001 resource_idx = ins->src[0].reg.idx[0].offset;
6002
6003 shader_addline(buffer, "ivec2(");
6004 if (ins->src[0].reg.type == WINED3DSPR_RESOURCE)
6005 {
6006 unsigned int bind_idx = shader_glsl_find_sampler(&ins->ctx->reg_maps->sampler_map,
6007 resource_idx, WINED3D_SAMPLER_DEFAULT);
6008 shader_addline(buffer, "textureSize(%s_sampler%u)", prefix, bind_idx);
6009 }
6010 else
6011 {
6012 shader_addline(buffer, "imageSize(%s_image%u)", prefix, resource_idx);
6013 }
6014 if (resource_info->stride)
6015 shader_addline(buffer, " / %u", resource_info->stride);
6016 else if (resource_info->flags & WINED3D_VIEW_BUFFER_RAW)
6017 shader_addline(buffer, " * 4");
6018 shader_addline(buffer, ", %u)%s);\n", resource_info->stride, dst_swizzle);
6019}
static const struct wined3d_shader_resource_info * shader_glsl_get_resource_info(const struct wined3d_shader_instruction *ins, const struct wined3d_shader_register *reg)
Definition: glsl_shader.c:5957
static unsigned int shader_glsl_find_sampler(const struct wined3d_shader_sampler_map *sampler_map, unsigned int resource_idx, unsigned int sampler_idx)
Definition: glsl_shader.c:5500
#define WINED3D_SAMPLER_DEFAULT
@ WINED3DSPR_RESOURCE

◆ shader_glsl_call()

static void shader_glsl_call ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5311 of file glsl_shader.c.

5312{
5313 shader_addline(ins->ctx->buffer, "subroutine%u();\n", ins->src[0].reg.idx[0].offset);
5314}

◆ shader_glsl_callnz()

static void shader_glsl_callnz ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5316 of file glsl_shader.c.

5317{
5318 struct glsl_src_param src1_param;
5319
5320 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0, &src1_param);
5321 shader_addline(ins->ctx->buffer, "if (%s) subroutine%u();\n",
5322 src1_param.param_str, ins->src[0].reg.idx[0].offset);
5323}

◆ shader_glsl_case()

static void shader_glsl_case ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5186 of file glsl_shader.c.

5187{
5188 struct glsl_src_param src0_param;
5189
5190 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
5191 shader_addline(ins->ctx->buffer, "case %s:\n", src0_param.param_str);
5192}

◆ shader_glsl_cast()

static void shader_glsl_cast ( const struct wined3d_shader_instruction *  ins,
const char *  vector_constructor,
const char *  scalar_constructor 
)
static

Definition at line 4471 of file glsl_shader.c.

4473{
4474 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4475 struct glsl_src_param src_param;
4476 unsigned int mask_size;
4477 DWORD write_mask;
4478
4479 write_mask = shader_glsl_append_dst(buffer, ins);
4480 mask_size = shader_glsl_get_write_mask_size(write_mask);
4481 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src_param);
4482
4483 if (mask_size > 1)
4484 shader_addline(buffer, "%s%u(%s));\n", vector_constructor, mask_size, src_param.param_str);
4485 else
4486 shader_addline(buffer, "%s(%s));\n", scalar_constructor, src_param.param_str);
4487}
static unsigned int shader_glsl_get_write_mask_size(DWORD write_mask)
Definition: glsl_shader.c:3298

Referenced by shader_glsl_to_float().

◆ shader_glsl_clip_plane_uniform()

static void shader_glsl_clip_plane_uniform ( const struct wined3d_context_gl *  context_gl,
const struct wined3d_state *  state,
unsigned int  index,
struct glsl_shader_prog_link *  prog 
)
static

Definition at line 1708 of file glsl_shader.c.

1710{
1711 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1712
1713 GL_EXTCALL(glUniform4fv(prog->vs.clip_planes_location + index, 1, &state->clip_planes[index].x));
1714}

Referenced by shader_glsl_load_constants().

◆ shader_glsl_cnd()

static void shader_glsl_cnd ( const struct wined3d_shader_instruction *  ins)
static

Process the CND opcode in GLSL (dst = (src0 > 0.5) ? src1 : src2)

Definition at line 4742 of file glsl_shader.c.

4743{
4744 struct glsl_src_param src0_param;
4745 struct glsl_src_param src1_param;
4746 struct glsl_src_param src2_param;
4747 DWORD write_mask;
4748 DWORD shader_version = WINED3D_SHADER_VERSION(ins->ctx->reg_maps->shader_version.major,
4749 ins->ctx->reg_maps->shader_version.minor);
4750
4751 if (shader_version < WINED3D_SHADER_VERSION(1, 4))
4752 {
4753 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
4754 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
4755 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
4756 shader_glsl_add_src_param(ins, &ins->src[2], write_mask, &src2_param);
4757
4758 if (ins->coissue && ins->dst->write_mask != WINED3DSP_WRITEMASK_3)
4759 shader_addline(ins->ctx->buffer, "%s /* COISSUE! */);\n", src1_param.param_str);
4760 else
4761 shader_addline(ins->ctx->buffer, "%s > 0.5 ? %s : %s);\n",
4762 src0_param.param_str, src1_param.param_str, src2_param.param_str);
4763 return;
4764 }
4765
4767}
static void shader_glsl_conditional_move(const struct wined3d_shader_instruction *ins)
Definition: glsl_shader.c:4635
#define WINED3DSP_WRITEMASK_3
#define WINED3D_SHADER_VERSION(major, minor)

◆ shader_glsl_color_correction()

static void shader_glsl_color_correction ( const struct wined3d_shader_instruction *  ins,
struct color_fixup_desc  fixup 
)
static

Definition at line 3785 of file glsl_shader.c.

3786{
3787 struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
3789
3791 shader_glsl_get_register_name(&ins->dst[0].reg, ins->dst[0].reg.data_type, reg_name, NULL, ins->ctx);
3792 shader_glsl_color_correction_ext(ins->ctx->buffer, reg_name->buffer, ins->dst[0].write_mask, fixup);
3794}

Referenced by PRINTF_ATTR().

◆ shader_glsl_color_correction_ext()

static void shader_glsl_color_correction_ext ( struct wined3d_string_buffer *  buffer,
const char *  reg_name,
DWORD  mask,
struct color_fixup_desc  fixup 
)
static

Definition at line 3731 of file glsl_shader.c.

3733{
3734 unsigned int mask_size, remaining;
3735 DWORD fixup_mask = 0;
3736 char arguments[256];
3737 char mask_str[6];
3738
3743 if (!(mask &= fixup_mask))
3744 return;
3745
3746 if (is_complex_fixup(fixup))
3747 {
3749 FIXME("Complex fixup (%#x) not supported\n",complex_fixup);
3750 return;
3751 }
3752
3755
3756 arguments[0] = '\0';
3757 remaining = mask_size;
3759 {
3761 if (--remaining) strcat(arguments, ", ");
3762 }
3764 {
3766 if (--remaining) strcat(arguments, ", ");
3767 }
3769 {
3771 if (--remaining) strcat(arguments, ", ");
3772 }
3774 {
3776 if (--remaining) strcat(arguments, ", ");
3777 }
3778
3779 if (mask_size > 1)
3780 shader_addline(buffer, "%s%s = vec%u(%s);\n", reg_name, mask_str, mask_size, arguments);
3781 else
3782 shader_addline(buffer, "%s%s = %s;\n", reg_name, mask_str, arguments);
3783}
static WCHAR * fixup_mask(const WCHAR *mask)
Definition: file.c:1154
static void shader_glsl_append_fixup_arg(char *arguments, const char *reg_name, BOOL sign_fixup, enum fixup_channel_source channel_source)
Definition: glsl_shader.c:3689
static void shader_glsl_write_mask_to_str(DWORD write_mask, char *str)
Definition: glsl_shader.c:3270
unsigned short x_source
unsigned short y_sign_fixup
unsigned short w_source
unsigned short x_sign_fixup
unsigned short z_sign_fixup
unsigned short y_source
unsigned short w_sign_fixup
unsigned short z_source
static BOOL is_complex_fixup(struct color_fixup_desc fixup)
#define WINED3DSP_WRITEMASK_2

Referenced by glsl_blitter_generate_plain_shader(), shader_glsl_color_correction(), and shader_glsl_generate_ffp_fragment_shader().

◆ shader_glsl_color_fixup_supported()

static BOOL shader_glsl_color_fixup_supported ( struct color_fixup_desc  fixup)
static

Definition at line 11420 of file glsl_shader.c.

11421{
11422 /* We support everything except YUV conversions. */
11423 return !is_complex_fixup(fixup);
11424}

◆ shader_glsl_compare()

static void shader_glsl_compare ( const struct wined3d_shader_instruction *  ins)
static

Process signed comparison opcodes in GLSL.

Definition at line 4533 of file glsl_shader.c.

4534{
4535 struct glsl_src_param src0_param;
4536 struct glsl_src_param src1_param;
4537 DWORD write_mask;
4538 unsigned int mask_size;
4539
4540 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
4541 mask_size = shader_glsl_get_write_mask_size(write_mask);
4542 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
4543 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
4544
4545 if (mask_size > 1) {
4546 const char *compare;
4547
4548 switch(ins->handler_idx)
4549 {
4550 case WINED3DSIH_SLT: compare = "lessThan"; break;
4551 case WINED3DSIH_SGE: compare = "greaterThanEqual"; break;
4552 default: compare = "";
4553 FIXME("Can't handle opcode %s.\n", debug_d3dshaderinstructionhandler(ins->handler_idx));
4554 }
4555
4556 shader_addline(ins->ctx->buffer, "vec%d(%s(%s, %s)));\n", mask_size, compare,
4557 src0_param.param_str, src1_param.param_str);
4558 } else {
4559 switch(ins->handler_idx)
4560 {
4561 case WINED3DSIH_SLT:
4562 /* Step(src0, src1) is not suitable here because if src0 == src1 SLT is supposed,
4563 * to return 0.0 but step returns 1.0 because step is not < x
4564 * An alternative is a bvec compare padded with an unused second component.
4565 * step(src1 * -1.0, src0 * -1.0) is not an option because it suffers from the same
4566 * issue. Playing with not() is not possible either because not() does not accept
4567 * a scalar.
4568 */
4569 shader_addline(ins->ctx->buffer, "(%s < %s) ? 1.0 : 0.0);\n",
4570 src0_param.param_str, src1_param.param_str);
4571 break;
4572 case WINED3DSIH_SGE:
4573 /* Here we can use the step() function and safe a conditional */
4574 shader_addline(ins->ctx->buffer, "step(%s, %s));\n", src1_param.param_str, src0_param.param_str);
4575 break;
4576 default:
4577 FIXME("Can't handle opcode %s.\n", debug_d3dshaderinstructionhandler(ins->handler_idx));
4578 }
4579
4580 }
4581}
#define compare
Definition: bug.cpp:8
@ WINED3DSIH_SLT
@ WINED3DSIH_SGE

◆ shader_glsl_compile()

static void shader_glsl_compile ( const struct wined3d_gl_info *  gl_info,
GLuint  shader,
const char *  src 
)
static

Definition at line 537 of file glsl_shader.c.

538{
539 const char *ptr, *end, *line;
540
541 TRACE("Compiling shader object %u.\n", shader);
542
543 if (TRACE_ON(d3d_shader))
544 {
545 ptr = src;
546 end = ptr + strlen(ptr);
547 while ((line = wined3d_get_line(&ptr, end)))
548 {
549 TRACE_(d3d_shader)(" %.*s", (int)(ptr - line), line);
550 }
551 }
552
553 GL_EXTCALL(glShaderSource(shader, 1, &src, NULL));
554 checkGLcall("glShaderSource");
555 GL_EXTCALL(glCompileShader(shader));
556 checkGLcall("glCompileShader");
558}
#define TRACE_(x)
Definition: compat.h:76
#define TRACE_ON(x)
Definition: compat.h:75
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by shader_glsl_generate_compute_shader(), shader_glsl_generate_domain_shader(), shader_glsl_generate_ffp_fragment_shader(), shader_glsl_generate_ffp_vertex_shader(), shader_glsl_generate_fragment_shader(), shader_glsl_generate_geometry_shader(), shader_glsl_generate_hull_shader(), shader_glsl_generate_vertex_shader(), and shader_glsl_generate_vs3_rasterizer_input_setup().

◆ shader_glsl_compile_compute_shader()

static HRESULT shader_glsl_compile_compute_shader ( struct shader_glsl_priv *  priv,
const struct wined3d_context_gl *  context_gl,
struct wined3d_shader *  shader 
)
static

Definition at line 10274 of file glsl_shader.c.

10276{
10277 struct glsl_context_data *ctx_data = context_gl->c.shader_backend_data;
10278 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
10280 struct glsl_cs_compiled_shader *gl_shaders;
10281 struct glsl_shader_private *shader_data;
10283 GLuint shader_id, program_id;
10284
10285 if (!(entry = malloc(sizeof(*entry))))
10286 {
10287 ERR("Out of memory.\n");
10288 return E_OUTOFMEMORY;
10289 }
10290
10291 if (!(shader->backend_data = calloc(1, sizeof(*shader_data))))
10292 {
10293 ERR("Failed to allocate backend data.\n");
10294 free(entry);
10295 return E_OUTOFMEMORY;
10296 }
10297 shader_data = shader->backend_data;
10298
10299 if (!(shader_data->gl_shaders.cs = malloc(sizeof(*gl_shaders))))
10300 {
10301 ERR("Failed to allocate GL shader array.\n");
10302 free(entry);
10303 free(shader->backend_data);
10304 shader->backend_data = NULL;
10305 return E_OUTOFMEMORY;
10306 }
10307 shader_data->shader_array_size = 1;
10308 gl_shaders = shader_data->gl_shaders.cs;
10309
10310 TRACE("Compiling compute shader %p.\n", shader);
10311
10313 shader_id = shader_glsl_generate_compute_shader(context_gl, priv, shader);
10314 gl_shaders[shader_data->num_gl_shaders++].id = shader_id;
10315
10316 program_id = GL_EXTCALL(glCreateProgram());
10317 TRACE("Created new GLSL shader program %u.\n", program_id);
10318
10319 entry->id = program_id;
10320 entry->vs.id = 0;
10321 entry->hs.id = 0;
10322 entry->ds.id = 0;
10323 entry->gs.id = 0;
10324 entry->ps.id = 0;
10325 entry->cs.id = shader_id;
10326 entry->constant_version = 0;
10327 entry->shader_controlled_clip_distances = 0;
10329
10330 TRACE("Attaching GLSL shader object %u to program %u.\n", shader_id, program_id);
10331 GL_EXTCALL(glAttachShader(program_id, shader_id));
10332 checkGLcall("glAttachShader");
10333
10334 list_add_head(&shader->linked_programs, &entry->cs.shader_entry);
10335
10336 TRACE("Linking GLSL shader program %u.\n", program_id);
10337 GL_EXTCALL(glLinkProgram(program_id));
10338 shader_glsl_validate_link(gl_info, program_id);
10339
10340 GL_EXTCALL(glUseProgram(program_id));
10341 checkGLcall("glUseProgram");
10342 shader_glsl_load_program_resources(context_gl, priv, program_id, shader);
10343 shader_glsl_load_images(gl_info, priv, program_id, &shader->reg_maps);
10344
10345 entry->constant_update_mask = 0;
10346
10347 GL_EXTCALL(glUseProgram(ctx_data->glsl_program ? ctx_data->glsl_program->id : 0));
10348 checkGLcall("glUseProgram");
10349 return WINED3D_OK;
10350}
static GLuint shader_glsl_generate_compute_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader)
Definition: glsl_shader.c:8639

Referenced by find_glsl_compute_shader(), and shader_glsl_precompile().

◆ shader_glsl_conditional_move()

static void shader_glsl_conditional_move ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4635 of file glsl_shader.c.

4636{
4637 const char *condition_prefix, *condition_suffix;
4639 struct glsl_src_param src0_param;
4640 struct glsl_src_param src1_param;
4641 struct glsl_src_param src2_param;
4642 BOOL temp_destination = FALSE;
4643 DWORD cmp_channel = 0;
4644 unsigned int i, j;
4645 char mask_char[6];
4646 DWORD write_mask;
4647
4648 switch (ins->handler_idx)
4649 {
4650 case WINED3DSIH_CMP:
4651 condition_prefix = "";
4652 condition_suffix = " >= 0.0";
4653 break;
4654
4655 case WINED3DSIH_CND:
4656 condition_prefix = "";
4657 condition_suffix = " > 0.5";
4658 break;
4659
4660 case WINED3DSIH_MOVC:
4661 condition_prefix = "bool(";
4662 condition_suffix = ")";
4663 break;
4664
4665 default:
4666 FIXME("Unhandled instruction %#x.\n", ins->handler_idx);
4667 condition_prefix = "<unhandled prefix>";
4668 condition_suffix = "<unhandled suffix>";
4669 break;
4670 }
4671
4672 if (shader_is_scalar(&ins->dst[0].reg) || shader_is_scalar(&ins->src[0].reg))
4673 {
4674 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
4675 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
4676 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
4677 shader_glsl_add_src_param(ins, &ins->src[2], write_mask, &src2_param);
4678
4679 shader_addline(ins->ctx->buffer, "%s%s%s ? %s : %s);\n",
4680 condition_prefix, src0_param.param_str, condition_suffix,
4681 src1_param.param_str, src2_param.param_str);
4682 return;
4683 }
4684
4685 dst = ins->dst[0];
4686
4687 /* Splitting the instruction up in multiple lines imposes a problem:
4688 * The first lines may overwrite source parameters of the following lines.
4689 * Deal with that by using a temporary destination register if needed. */
4690 if ((ins->src[0].reg.idx[0].offset == dst.reg.idx[0].offset
4691 && ins->src[0].reg.type == dst.reg.type)
4692 || (ins->src[1].reg.idx[0].offset == dst.reg.idx[0].offset
4693 && ins->src[1].reg.type == dst.reg.type)
4694 || (ins->src[2].reg.idx[0].offset == dst.reg.idx[0].offset
4695 && ins->src[2].reg.type == dst.reg.type))
4696 temp_destination = TRUE;
4697
4698 /* Cycle through all source0 channels. */
4699 for (i = 0; i < 4; ++i)
4700 {
4701 write_mask = 0;
4702 /* Find the destination channels which use the current source0 channel. */
4703 for (j = 0; j < 4; ++j)
4704 {
4705 if (shader_glsl_swizzle_get_component(ins->src[0].swizzle, j) == i)
4706 {
4707 write_mask |= WINED3DSP_WRITEMASK_0 << j;
4708 cmp_channel = WINED3DSP_WRITEMASK_0 << j;
4709 }
4710 }
4711 dst.write_mask = ins->dst[0].write_mask & write_mask;
4712
4713 if (temp_destination)
4714 {
4715 if (!(write_mask = shader_glsl_get_write_mask(&dst, mask_char)))
4716 continue;
4717 shader_addline(ins->ctx->buffer, "tmp0%s = (", mask_char);
4718 }
4719 else if (!(write_mask = shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &dst, 0, dst.reg.data_type)))
4720 continue;
4721
4722 shader_glsl_add_src_param(ins, &ins->src[0], cmp_channel, &src0_param);
4723 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
4724 shader_glsl_add_src_param(ins, &ins->src[2], write_mask, &src2_param);
4725
4726 shader_addline(ins->ctx->buffer, "%s%s%s ? %s : %s);\n",
4727 condition_prefix, src0_param.param_str, condition_suffix,
4728 src1_param.param_str, src2_param.param_str);
4729 }
4730
4731 if (temp_destination)
4732 {
4733 shader_glsl_get_write_mask(&ins->dst[0], mask_char);
4734 shader_glsl_append_dst(ins->ctx->buffer, ins);
4735 shader_addline(ins->ctx->buffer, "tmp0%s);\n", mask_char);
4736 }
4737}
static unsigned int shader_glsl_swizzle_get_component(DWORD swizzle, unsigned int component_idx)
Definition: glsl_shader.c:3310
@ WINED3DSIH_MOVC
@ WINED3DSIH_CMP
@ WINED3DSIH_CND
static BOOL shader_is_scalar(const struct wined3d_shader_register *reg)

Referenced by shader_glsl_cnd().

◆ shader_glsl_conditional_op()

static void shader_glsl_conditional_op ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5266 of file glsl_shader.c.

5267{
5268 const char *op;
5269
5270 switch (ins->handler_idx)
5271 {
5272 case WINED3DSIH_BREAKP:
5273 op = "break;";
5274 break;
5276 op = "continue;";
5277 break;
5278 case WINED3DSIH_RETP:
5279 op = "return;";
5280 break;
5281 default:
5282 ERR("Unhandled opcode %#x.\n", ins->handler_idx);
5283 return;
5284 }
5285
5287 if (ins->handler_idx == WINED3DSIH_RETP)
5288 {
5289 shader_addline(ins->ctx->buffer, "{\n");
5291 }
5292 shader_addline(ins->ctx->buffer, " %s\n", op);
5293 if (ins->handler_idx == WINED3DSIH_RETP)
5294 shader_addline(ins->ctx->buffer, "}\n");
5295}
static void shader_glsl_generate_shader_epilogue(const struct wined3d_shader_context *ctx)
Definition: glsl_shader.c:8611
static void shader_glsl_generate_condition(const struct wined3d_shader_instruction *ins)
Definition: glsl_shader.c:5199
@ WINED3DSIH_CONTINUEP
@ WINED3DSIH_BREAKP
@ WINED3DSIH_RETP

◆ shader_glsl_continue()

static void shader_glsl_continue ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5297 of file glsl_shader.c.

5298{
5299 shader_addline(ins->ctx->buffer, "continue;\n");
5300}

◆ shader_glsl_cross()

static void shader_glsl_cross ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4164 of file glsl_shader.c.

4165{
4167 struct glsl_src_param src0_param;
4168 struct glsl_src_param src1_param;
4169 char dst_mask[6];
4170
4171 shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
4172 shader_glsl_append_dst(ins->ctx->buffer, ins);
4173 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
4174 shader_glsl_add_src_param(ins, &ins->src[1], src_mask, &src1_param);
4175 shader_addline(ins->ctx->buffer, "cross(%s, %s)%s);\n", src0_param.param_str, src1_param.param_str, dst_mask);
4176}
UCHAR src_mask[]
Definition: GetObject.c:14

◆ shader_glsl_cut()

static void shader_glsl_cut ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4178 of file glsl_shader.c.

4179{
4180 unsigned int stream = ins->handler_idx == WINED3DSIH_CUT ? 0 : ins->src[0].reg.idx[0].offset;
4181
4182 if (!stream)
4183 shader_addline(ins->ctx->buffer, "EndPrimitive();\n");
4184 else
4185 FIXME("Unhandled primitive stream %u.\n", stream);
4186}
Definition: parse.h:23
@ WINED3DSIH_CUT

◆ shader_glsl_declare_generic_vertex_attribute()

static void shader_glsl_declare_generic_vertex_attribute ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info,
const struct wined3d_shader_signature_element *  e 
)
static

Definition at line 2332 of file glsl_shader.c.

2334{
2335 unsigned int index = e->register_idx;
2337
2338 if (e->sysval_semantic == WINED3D_SV_VERTEX_ID)
2339 {
2340 shader_addline(buffer, "uniform int base_vertex_id;\n");
2341 shader_addline(buffer, "vec4 vs_in%u = vec4(intBitsToFloat(gl_VertexID - base_vertex_id), 0.0, 0.0, 0.0);\n", index);
2342 return;
2343 }
2344 if (e->sysval_semantic == WINED3D_SV_INSTANCE_ID)
2345 {
2346 shader_addline(buffer, "vec4 vs_in%u = vec4(intBitsToFloat(gl_InstanceID), 0.0, 0.0, 0.0);\n",
2347 index);
2348 return;
2349 }
2350 if (e->sysval_semantic && e->sysval_semantic != WINED3D_SV_POSITION)
2351 FIXME("Unhandled sysval semantic %#x.\n", e->sysval_semantic);
2352
2354 shader_addline(buffer, "layout(location = %u) ", index);
2355
2356 type = e->component_type;
2357 if ((unsigned int)type >= ARRAY_SIZE(component_type_info))
2358 {
2359 FIXME("Unhandled type %#x.\n", type);
2361 }
2363 shader_addline(buffer, "%s vec4 vs_in%u;\n", get_attribute_keyword(gl_info), index);
2364 else
2368}
const char * glsl_scalar_type
Definition: glsl_shader.c:72
static const struct @336 component_type_info[]
static void shader_glsl_declare_typed_vertex_attribute(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const char *vector_type, const char *scalar_type, unsigned int index)
Definition: glsl_shader.c:2322
const char * glsl_vector_type
Definition: glsl_shader.c:73
#define e
Definition: ke_i.h:82
wined3d_component_type
@ WINED3D_TYPE_UNKNOWN
@ WINED3D_TYPE_FLOAT
@ WINED3D_SV_INSTANCE_ID
@ WINED3D_SV_POSITION
@ WINED3D_SV_VERTEX_ID

Referenced by shader_glsl_generate_vertex_shader().

◆ shader_glsl_declare_shader_inputs()

static void shader_glsl_declare_shader_inputs ( const struct wined3d_gl_info *  gl_info,
struct wined3d_string_buffer *  buffer,
unsigned int  element_count,
const uint32_t *  interpolation_mode,
BOOL  unroll 
)
static

Definition at line 2181 of file glsl_shader.c.

2184{
2186 unsigned int i;
2187
2189 {
2190 if (unroll)
2191 {
2192 shader_addline(buffer, "in shader_in_out {\n");
2193 for (i = 0; i < element_count; ++i)
2194 {
2195 mode = wined3d_extract_interpolation_mode(interpolation_mode, i);
2197 }
2198 shader_addline(buffer, "} shader_in;\n");
2199 }
2200 else
2201 {
2202 shader_addline(buffer, "in shader_in_out { vec4 reg[%u]; } shader_in;\n", element_count);
2203 }
2204 }
2205 else
2206 {
2207 declare_in_varying(gl_info, buffer, FALSE, "vec4 ps_link[%u];\n", element_count);
2208 }
2209}
GLenum mode
Definition: glext.h:6217
static const char * shader_glsl_interpolation_qualifiers(enum wined3d_shader_interpolation_mode mode)
Definition: glsl_shader.c:2158
static enum wined3d_shader_interpolation_mode wined3d_extract_interpolation_mode(const uint32_t *packed_interpolation_mode, unsigned int register_idx)
Definition: glsl_shader.c:2174
static BOOL shader_glsl_use_interface_blocks(const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:2098
static ULONG ** element_count
Definition: exception.c:124
wined3d_shader_interpolation_mode

Referenced by shader_glsl_generate_fragment_shader().

◆ shader_glsl_declare_shader_outputs()

static void shader_glsl_declare_shader_outputs ( const struct wined3d_gl_info *  gl_info,
struct wined3d_string_buffer *  buffer,
unsigned int  element_count,
BOOL  rasterizer_setup,
const uint32_t *  interpolation_mode 
)
static

Definition at line 2219 of file glsl_shader.c.

2222{
2224 unsigned int i;
2225
2227 {
2228 if (rasterizer_setup)
2229 {
2230 shader_addline(buffer, "out shader_in_out {\n");
2231 for (i = 0; i < element_count; ++i)
2232 {
2233 const char *interpolation_qualifiers = "";
2235 {
2236 mode = wined3d_extract_interpolation_mode(interpolation_mode, i);
2237 interpolation_qualifiers = shader_glsl_interpolation_qualifiers(mode);
2238 }
2239 shader_addline(buffer, " %svec4 reg%u;\n", interpolation_qualifiers, i);
2240 }
2241 shader_addline(buffer, "} shader_out;\n");
2242 }
2243 else
2244 {
2245 shader_addline(buffer, "out shader_in_out { vec4 reg[%u]; } shader_out;\n", element_count);
2246 }
2247 }
2248 else
2249 {
2250 declare_out_varying(gl_info, buffer, FALSE, "vec4 ps_link[%u];\n", element_count);
2251 }
2252}
static BOOL needs_interpolation_qualifiers_for_shader_outputs(const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:2211

Referenced by shader_glsl_generate_sm4_output_setup(), and shader_glsl_generate_vs3_rasterizer_input_setup().

◆ shader_glsl_declare_typed_vertex_attribute()

static void shader_glsl_declare_typed_vertex_attribute ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info,
const char *  vector_type,
const char *  scalar_type,
unsigned int  index 
)
static

Definition at line 2322 of file glsl_shader.c.

2325{
2326 shader_addline(buffer, "%s %s4 vs_in_%s%u;\n",
2327 get_attribute_keyword(gl_info), vector_type, scalar_type, index);
2328 shader_addline(buffer, "vec4 vs_in%u = %sBitsToFloat(vs_in_%s%u);\n",
2329 index, scalar_type, scalar_type, index);
2330}

Referenced by shader_glsl_declare_generic_vertex_attribute().

◆ shader_glsl_default()

static void shader_glsl_default ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5194 of file glsl_shader.c.

5195{
5196 shader_addline(ins->ctx->buffer, "default:\n");
5197}

◆ shader_glsl_destroy()

static void shader_glsl_destroy ( struct wined3d_shader *  shader)
static

Definition at line 10992 of file glsl_shader.c.

10993{
10994 struct glsl_shader_private *shader_data = shader->backend_data;
10995 struct wined3d_device *device = shader->device;
10996 struct shader_glsl_priv *priv = device->shader_priv;
10997 const struct wined3d_gl_info *gl_info;
10998 const struct list *linked_programs;
10999 struct wined3d_context *context;
11000
11001 if (!shader_data || !shader_data->num_gl_shaders)
11002 {
11003 free(shader_data);
11004 shader->backend_data = NULL;
11005 return;
11006 }
11007
11010
11011 TRACE("Deleting linked programs.\n");
11012 linked_programs = &shader->linked_programs;
11013 if (!list_empty(linked_programs))
11014 {
11015 struct glsl_shader_prog_link *entry, *entry2;
11016 UINT i;
11017
11018 switch (shader->reg_maps.shader_version.type)
11019 {
11021 {
11022 struct glsl_ps_compiled_shader *gl_shaders = shader_data->gl_shaders.ps;
11023
11024 for (i = 0; i < shader_data->num_gl_shaders; ++i)
11025 {
11026 TRACE("Deleting pixel shader %u.\n", gl_shaders[i].id);
11027 GL_EXTCALL(glDeleteShader(gl_shaders[i].id));
11028 checkGLcall("glDeleteShader");
11029 }
11030 free(shader_data->gl_shaders.ps);
11031
11032 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs,
11033 struct glsl_shader_prog_link, ps.shader_entry)
11034 {
11036 delete_glsl_program_entry(priv, gl_info, entry);
11037 }
11038
11039 break;
11040 }
11041
11043 {
11044 struct glsl_vs_compiled_shader *gl_shaders = shader_data->gl_shaders.vs;
11045
11046 for (i = 0; i < shader_data->num_gl_shaders; ++i)
11047 {
11048 TRACE("Deleting vertex shader %u.\n", gl_shaders[i].id);
11049 GL_EXTCALL(glDeleteShader(gl_shaders[i].id));
11050 checkGLcall("glDeleteShader");
11051 }
11052 free(shader_data->gl_shaders.vs);
11053
11054 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs,
11055 struct glsl_shader_prog_link, vs.shader_entry)
11056 {
11058 delete_glsl_program_entry(priv, gl_info, entry);
11059 }
11060
11061 break;
11062 }
11063
11065 {
11066 struct glsl_hs_compiled_shader *gl_shaders = shader_data->gl_shaders.hs;
11067
11068 for (i = 0; i < shader_data->num_gl_shaders; ++i)
11069 {
11070 TRACE("Deleting hull shader %u.\n", gl_shaders[i].id);
11071 GL_EXTCALL(glDeleteShader(gl_shaders[i].id));
11072 checkGLcall("glDeleteShader");
11073 }
11074 free(shader_data->gl_shaders.hs);
11075
11076 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs,
11077 struct glsl_shader_prog_link, hs.shader_entry)
11078 {
11080 delete_glsl_program_entry(priv, gl_info, entry);
11081 }
11082
11083 break;
11084 }
11085
11087 {
11088 struct glsl_ds_compiled_shader *gl_shaders = shader_data->gl_shaders.ds;
11089
11090 for (i = 0; i < shader_data->num_gl_shaders; ++i)
11091 {
11092 TRACE("Deleting domain shader %u.\n", gl_shaders[i].id);
11093 GL_EXTCALL(glDeleteShader(gl_shaders[i].id));
11094 checkGLcall("glDeleteShader");
11095 }
11096 free(shader_data->gl_shaders.ds);
11097
11098 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs,
11099 struct glsl_shader_prog_link, ds.shader_entry)
11100 {
11102 delete_glsl_program_entry(priv, gl_info, entry);
11103 }
11104
11105 break;
11106 }
11107
11109 {
11110 struct glsl_gs_compiled_shader *gl_shaders = shader_data->gl_shaders.gs;
11111
11112 for (i = 0; i < shader_data->num_gl_shaders; ++i)
11113 {
11114 TRACE("Deleting geometry shader %u.\n", gl_shaders[i].id);
11115 GL_EXTCALL(glDeleteShader(gl_shaders[i].id));
11116 checkGLcall("glDeleteShader");
11117 }
11118 free(shader_data->gl_shaders.gs);
11119
11120 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs,
11121 struct glsl_shader_prog_link, gs.shader_entry)
11122 {
11124 delete_glsl_program_entry(priv, gl_info, entry);
11125 }
11126
11127 break;
11128 }
11129
11131 {
11132 struct glsl_cs_compiled_shader *gl_shaders = shader_data->gl_shaders.cs;
11133
11134 for (i = 0; i < shader_data->num_gl_shaders; ++i)
11135 {
11136 TRACE("Deleting compute shader %u.\n", gl_shaders[i].id);
11137 GL_EXTCALL(glDeleteShader(gl_shaders[i].id));
11138 checkGLcall("glDeleteShader");
11139 }
11140 free(shader_data->gl_shaders.cs);
11141
11142 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs,
11143 struct glsl_shader_prog_link, cs.shader_entry)
11144 {
11146 delete_glsl_program_entry(priv, gl_info, entry);
11147 }
11148
11149 break;
11150 }
11151
11152 default:
11153 ERR("Unhandled shader type %#x.\n", shader->reg_maps.shader_version.type);
11154 break;
11155 }
11156 }
11157
11158 free(shader->backend_data);
11159 shader->backend_data = NULL;
11160
11162}
static int list_empty(struct list_entry *head)
Definition: list.h:58
static void shader_glsl_invalidate_contexts_program(struct wined3d_device *device, const struct glsl_shader_prog_link *program)
static void delete_glsl_program_entry(struct shader_glsl_priv *priv, const struct wined3d_gl_info *gl_info, struct glsl_shader_prog_link *entry)
Definition: glsl_shader.c:7069
#define ds
Definition: i386-dis.c:443
#define cs
Definition: i386-dis.c:442
#define gs
Definition: i386-dis.c:445
static vector_t * vs
Definition: server.c:146
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:242
static void context_release(struct wined3d_context *context)
static struct wined3d_context * context_acquire(struct wined3d_device *device, struct wined3d_texture *texture, unsigned int sub_resource_idx)

◆ shader_glsl_disable()

static void shader_glsl_disable ( void *  shader_priv,
struct wined3d_context *  context 
)
static

Definition at line 10953 of file glsl_shader.c.

10954{
10955 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
10956 struct glsl_context_data *ctx_data = context->shader_backend_data;
10957 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
10958 struct shader_glsl_priv *priv = shader_priv;
10959
10961 GL_EXTCALL(glUseProgram(0));
10962 checkGLcall("glUseProgram");
10963
10964 priv->vertex_pipe->vp_disable(context);
10965 priv->fragment_pipe->fp_disable(context);
10966
10968 {
10971 checkGLcall("glClampColorARB");
10972 }
10973}
#define GL_CLAMP_VERTEX_COLOR_ARB
Definition: glext.h:1622
static void shader_glsl_invalidate_current_program(struct wined3d_context *context)
@ ARB_COLOR_BUFFER_FLOAT
Definition: wined3d_gl.h:59

◆ shader_glsl_dot()

static void shader_glsl_dot ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4133 of file glsl_shader.c.

4134{
4135 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4136 struct glsl_src_param src0_param;
4137 struct glsl_src_param src1_param;
4138 DWORD dst_write_mask, src_write_mask;
4139 unsigned int dst_size;
4140
4141 dst_write_mask = shader_glsl_append_dst(buffer, ins);
4142 dst_size = shader_glsl_get_write_mask_size(dst_write_mask);
4143
4144 /* dp4 works on vec4, dp3 on vec3, etc. */
4145 if (ins->handler_idx == WINED3DSIH_DP4)
4146 src_write_mask = WINED3DSP_WRITEMASK_ALL;
4147 else if (ins->handler_idx == WINED3DSIH_DP3)
4149 else
4151
4152 shader_glsl_add_src_param(ins, &ins->src[0], src_write_mask, &src0_param);
4153 shader_glsl_add_src_param(ins, &ins->src[1], src_write_mask, &src1_param);
4154
4155 if (dst_size > 1) {
4156 shader_addline(buffer, "vec%d(dot(%s, %s)));\n", dst_size, src0_param.param_str, src1_param.param_str);
4157 } else {
4158 shader_addline(buffer, "dot(%s, %s));\n", src0_param.param_str, src1_param.param_str);
4159 }
4160}
@ WINED3DSIH_DP4
@ WINED3DSIH_DP3

Referenced by shader_glsl_mnxn().

◆ shader_glsl_dp2add()

static void shader_glsl_dp2add ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_DP2ADD instruction in GLSL. dst = dot2(src0, src1) + src2

Definition at line 6912 of file glsl_shader.c.

6913{
6914 struct glsl_src_param src0_param;
6915 struct glsl_src_param src1_param;
6916 struct glsl_src_param src2_param;
6917 DWORD write_mask;
6918 unsigned int mask_size;
6919
6920 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
6921 mask_size = shader_glsl_get_write_mask_size(write_mask);
6922
6925 shader_glsl_add_src_param(ins, &ins->src[2], WINED3DSP_WRITEMASK_0, &src2_param);
6926
6927 if (mask_size > 1) {
6928 shader_addline(ins->ctx->buffer, "vec%d(dot(%s, %s) + %s));\n",
6929 mask_size, src0_param.param_str, src1_param.param_str, src2_param.param_str);
6930 } else {
6931 shader_addline(ins->ctx->buffer, "dot(%s, %s) + %s);\n",
6932 src0_param.param_str, src1_param.param_str, src2_param.param_str);
6933 }
6934}

◆ shader_glsl_dst()

static void shader_glsl_dst ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_DST instruction in GLSL: dst.x = 1.0 dst.y = src0.x * src0.y dst.z = src0.z dst.w = src1.w

Definition at line 4923 of file glsl_shader.c.

4924{
4925 struct glsl_src_param src0y_param;
4926 struct glsl_src_param src0z_param;
4927 struct glsl_src_param src1y_param;
4928 struct glsl_src_param src1w_param;
4929 char dst_mask[6];
4930
4931 shader_glsl_append_dst(ins->ctx->buffer, ins);
4932 shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
4933
4934 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_1, &src0y_param);
4935 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_2, &src0z_param);
4936 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_1, &src1y_param);
4937 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_3, &src1w_param);
4938
4939 shader_addline(ins->ctx->buffer, "vec4(1.0, %s * %s, %s, %s))%s;\n",
4940 src0y_param.param_str, src1y_param.param_str, src0z_param.param_str, src1w_param.param_str, dst_mask);
4941}

◆ shader_glsl_dump_program_source()

static void shader_glsl_dump_program_source ( const struct wined3d_gl_info *  gl_info,
GLuint  program 
)
static

Definition at line 561 of file glsl_shader.c.

562{
563 GLint i, shader_count, source_size = -1;
565 char *source = NULL;
566
567 GL_EXTCALL(glGetProgramiv(program, GL_ATTACHED_SHADERS, &shader_count));
568 if (!(shaders = calloc(shader_count, sizeof(*shaders))))
569 {
570 ERR("Failed to allocate shader array memory.\n");
571 return;
572 }
573
574 GL_EXTCALL(glGetAttachedShaders(program, shader_count, NULL, shaders));
575 for (i = 0; i < shader_count; ++i)
576 {
577 const char *ptr, *end, *line;
578 GLint tmp;
579
580 GL_EXTCALL(glGetShaderiv(shaders[i], GL_SHADER_SOURCE_LENGTH, &tmp));
581
582 if (source_size < tmp)
583 {
584 free(source);
585
586 if (!(source = malloc(tmp)))
587 {
588 ERR("Failed to allocate %d bytes for shader source.\n", tmp);
589 free(shaders);
590 return;
591 }
592 source_size = tmp;
593 }
594
595 GL_EXTCALL(glGetShaderSource(shaders[i], source_size, NULL, source));
596 ptr = source;
597 end = &ptr[tmp - 1];
598
599 FIXME("Shader %u:\n", shaders[i]);
600 GL_EXTCALL(glGetShaderiv(shaders[i], GL_SHADER_TYPE, &tmp));
601 FIXME(" GL_SHADER_TYPE: %s.\n", debug_gl_shader_type(tmp));
602 GL_EXTCALL(glGetShaderiv(shaders[i], GL_COMPILE_STATUS, &tmp));
603 FIXME(" GL_COMPILE_STATUS: %d.\n", tmp);
604 FIXME("\n");
605 while ((line = wined3d_get_line(&ptr, end)))
606 {
607 FIXME(" %.*s", (int)(ptr - line), line);
608 }
609 FIXME("\n");
610 }
611
612 free(source);
613 free(shaders);
614}
const GLuint * shaders
Definition: glext.h:7538
#define GL_SHADER_SOURCE_LENGTH
Definition: glext.h:454
#define GL_COMPILE_STATUS
Definition: glext.h:447
#define GL_SHADER_TYPE
Definition: glext.h:426
#define GL_ATTACHED_SHADERS
Definition: glext.h:451
static const char * debug_gl_shader_type(GLenum type)
Definition: glsl_shader.c:353

Referenced by shader_glsl_validate_link().

◆ shader_glsl_else()

static void shader_glsl_else ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5227 of file glsl_shader.c.

5228{
5229 shader_addline(ins->ctx->buffer, "} else {\n");
5230}

◆ shader_glsl_emit()

static void shader_glsl_emit ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5232 of file glsl_shader.c.

5233{
5234 unsigned int stream = ins->handler_idx == WINED3DSIH_EMIT ? 0 : ins->src[0].reg.idx[0].offset;
5235 const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps;
5236 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
5237
5238 shader_addline(ins->ctx->buffer, "setup_gs_output(gs_out);\n");
5239 if (!priv->gl_info->supported[ARB_CLIP_CONTROL])
5240 shader_glsl_fixup_position(ins->ctx->buffer, reg_maps->viewport_array);
5241
5242 if (!stream)
5243 shader_addline(ins->ctx->buffer, "EmitVertex();\n");
5244 else
5245 FIXME("Unhandled primitive stream %u.\n", stream);
5246}
static void shader_glsl_fixup_position(struct wined3d_string_buffer *buffer, BOOL use_viewport_index)
Definition: glsl_shader.c:3861
const struct wined3d_gl_info * gl_info
Definition: glsl_shader.c:269
@ ARB_CLIP_CONTROL
Definition: wined3d_gl.h:58
@ WINED3DSIH_EMIT

◆ shader_glsl_enable_extensions()

static void shader_glsl_enable_extensions ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info 
)
static

Definition at line 7713 of file glsl_shader.c.

7715{
7716 if (gl_info->supported[ARB_CULL_DISTANCE])
7717 shader_addline(buffer, "#extension GL_ARB_cull_distance : enable\n");
7718 if (gl_info->supported[ARB_GPU_SHADER5])
7719 shader_addline(buffer, "#extension GL_ARB_gpu_shader5 : enable\n");
7721 shader_addline(buffer, "#extension GL_ARB_shader_atomic_counters : enable\n");
7722 if (gl_info->supported[ARB_SHADER_BIT_ENCODING])
7723 shader_addline(buffer, "#extension GL_ARB_shader_bit_encoding : enable\n");
7725 shader_addline(buffer, "#extension GL_ARB_shader_image_load_store : enable\n");
7726 if (gl_info->supported[ARB_SHADER_IMAGE_SIZE])
7727 shader_addline(buffer, "#extension GL_ARB_shader_image_size : enable\n");
7729 shader_addline(buffer, "#extension GL_ARB_shader_stencil_export : enable\n");
7731 shader_addline(buffer, "#extension GL_ARB_shader_storage_buffer_object : enable\n");
7733 shader_addline(buffer, "#extension GL_ARB_shader_texture_image_samples : enable\n");
7735 shader_addline(buffer, "#extension GL_ARB_shading_language_420pack : enable\n");
7737 shader_addline(buffer, "#extension GL_ARB_shading_language_packing : enable\n");
7739 shader_addline(buffer, "#extension GL_ARB_texture_cube_map_array : enable\n");
7740 if (gl_info->supported[ARB_TEXTURE_GATHER])
7741 shader_addline(buffer, "#extension GL_ARB_texture_gather : enable\n");
7742 if (gl_info->supported[ARB_TEXTURE_QUERY_LEVELS])
7743 shader_addline(buffer, "#extension GL_ARB_texture_query_levels : enable\n");
7745 shader_addline(buffer, "#extension GL_ARB_uniform_buffer_object : enable\n");
7746 if (gl_info->supported[ARB_VIEWPORT_ARRAY])
7747 shader_addline(buffer, "#extension GL_ARB_viewport_array : enable\n");
7748 if (gl_info->supported[EXT_GPU_SHADER4])
7749 shader_addline(buffer, "#extension GL_EXT_gpu_shader4 : enable\n");
7750 if (gl_info->supported[EXT_SHADER_INTEGER_MIX])
7751 shader_addline(buffer, "#extension GL_EXT_shader_integer_mix : enable\n");
7752 if (gl_info->supported[EXT_TEXTURE_ARRAY])
7753 shader_addline(buffer, "#extension GL_EXT_texture_array : enable\n");
7754 if (gl_info->supported[EXT_TEXTURE_SHADOW_LOD])
7755 shader_addline(buffer, "#extension GL_EXT_texture_shadow_lod : enable\n");
7756}
@ ARB_SHADING_LANGUAGE_PACKING
Definition: wined3d_gl.h:119
@ ARB_TEXTURE_QUERY_LEVELS
Definition: wined3d_gl.h:141
@ ARB_CULL_DISTANCE
Definition: wined3d_gl.h:64
@ ARB_SHADER_IMAGE_SIZE
Definition: wined3d_gl.h:112
@ ARB_SHADER_STORAGE_BUFFER_OBJECT
Definition: wined3d_gl.h:114
@ EXT_GPU_SHADER4
Definition: wined3d_gl.h:180
@ ARB_SHADER_TEXTURE_IMAGE_SAMPLES
Definition: wined3d_gl.h:115
@ ARB_UNIFORM_BUFFER_OBJECT
Definition: wined3d_gl.h:151
@ EXT_TEXTURE_SHADOW_LOD
Definition: wined3d_gl.h:199
@ ARB_SHADER_ATOMIC_COUNTERS
Definition: wined3d_gl.h:108
@ ARB_SHADING_LANGUAGE_420PACK
Definition: wined3d_gl.h:118
@ EXT_SHADER_INTEGER_MIX
Definition: wined3d_gl.h:187
@ ARB_TEXTURE_GATHER
Definition: wined3d_gl.h:136
@ ARB_VIEWPORT_ARRAY
Definition: wined3d_gl.h:158
@ ARB_SHADER_STENCIL_EXPORT
Definition: wined3d_gl.h:113
@ ARB_SHADER_IMAGE_LOAD_STORE
Definition: wined3d_gl.h:111
@ EXT_TEXTURE_ARRAY
Definition: wined3d_gl.h:191
@ ARB_TEXTURE_CUBE_MAP_ARRAY
Definition: wined3d_gl.h:131

Referenced by shader_glsl_generate_compute_shader(), shader_glsl_generate_domain_shader(), shader_glsl_generate_fragment_shader(), shader_glsl_generate_geometry_shader(), shader_glsl_generate_hull_shader(), and shader_glsl_generate_vertex_shader().

◆ shader_glsl_end()

static void shader_glsl_end ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5122 of file glsl_shader.c.

5123{
5124 struct wined3d_shader_parser_state *state = ins->ctx->state;
5125
5126 shader_addline(ins->ctx->buffer, "}\n");
5127
5128 if (ins->handler_idx == WINED3DSIH_ENDLOOP)
5129 {
5130 --state->current_loop_depth;
5131 --state->current_loop_reg;
5132 }
5133
5134 if (ins->handler_idx == WINED3DSIH_ENDREP)
5135 {
5136 --state->current_loop_depth;
5137 }
5138}
@ WINED3DSIH_ENDREP
@ WINED3DSIH_ENDLOOP

◆ shader_glsl_expp()

static void shader_glsl_expp ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_EXPP instruction in GLSL: For shader model 1.x, do the following (and honor the writemask, so use a temporary variable): dst.x = 2^(floor(src)) dst.y = src - floor(src) dst.z = 2^src (partial precision is allowed, but optional) dst.w = 1.0; For 2.0 shaders, just do this (honoring writemask and swizzle): dst = 2^src; (partial precision is allowed, but optional)

Definition at line 4448 of file glsl_shader.c.

4449{
4450 if (ins->ctx->reg_maps->shader_version.major < 2)
4451 {
4452 struct glsl_src_param src_param;
4453 char dst_mask[6];
4454
4455 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &src_param);
4456
4457 shader_addline(ins->ctx->buffer, "tmp0.x = exp2(floor(%s));\n", src_param.param_str);
4458 shader_addline(ins->ctx->buffer, "tmp0.y = %s - floor(%s);\n", src_param.param_str, src_param.param_str);
4459 shader_addline(ins->ctx->buffer, "tmp0.z = exp2(%s);\n", src_param.param_str);
4460 shader_addline(ins->ctx->buffer, "tmp0.w = 1.0;\n");
4461
4462 shader_glsl_append_dst(ins->ctx->buffer, ins);
4463 shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
4464 shader_addline(ins->ctx->buffer, "tmp0%s);\n", dst_mask);
4465 return;
4466 }
4467
4469}
static void shader_glsl_scalar_op(const struct wined3d_shader_instruction *ins)
Definition: glsl_shader.c:4384

◆ shader_glsl_ffp_fragment_op()

static void shader_glsl_ffp_fragment_op ( struct wined3d_string_buffer *  buffer,
unsigned int  stage,
BOOL  color,
BOOL  alpha,
BOOL  tmp_dst,
unsigned int  op,
DWORD  dw_arg0,
DWORD  dw_arg1,
DWORD  dw_arg2 
)
static

Definition at line 9541 of file glsl_shader.c.

9543{
9544 const char *dstmask, *dstreg, *arg0, *arg1, *arg2;
9545
9546 if (color && alpha)
9547 dstmask = "";
9548 else if (color)
9549 dstmask = ".xyz";
9550 else
9551 dstmask = ".w";
9552
9553 dstreg = tmp_dst ? "temp_reg" : "ret";
9554
9555 arg0 = shader_glsl_get_ffp_fragment_op_arg(buffer, 0, stage, dw_arg0);
9556 arg1 = shader_glsl_get_ffp_fragment_op_arg(buffer, 1, stage, dw_arg1);
9557 arg2 = shader_glsl_get_ffp_fragment_op_arg(buffer, 2, stage, dw_arg2);
9558
9559 switch (op)
9560 {
9562 break;
9563
9565 shader_addline(buffer, "%s%s = %s%s;\n", dstreg, dstmask, arg1, dstmask);
9566 break;
9567
9569 shader_addline(buffer, "%s%s = %s%s;\n", dstreg, dstmask, arg2, dstmask);
9570 break;
9571
9573 shader_addline(buffer, "%s%s = %s%s * %s%s;\n", dstreg, dstmask, arg1, dstmask, arg2, dstmask);
9574 break;
9575
9577 shader_addline(buffer, "%s%s = clamp(%s%s * %s%s * 4.0, 0.0, 1.0);\n",
9578 dstreg, dstmask, arg1, dstmask, arg2, dstmask);
9579 break;
9580
9582 shader_addline(buffer, "%s%s = clamp(%s%s * %s%s * 2.0, 0.0, 1.0);\n",
9583 dstreg, dstmask, arg1, dstmask, arg2, dstmask);
9584 break;
9585
9586 case WINED3D_TOP_ADD:
9587 shader_addline(buffer, "%s%s = clamp(%s%s + %s%s, 0.0, 1.0);\n",
9588 dstreg, dstmask, arg1, dstmask, arg2, dstmask);
9589 break;
9590
9592 shader_addline(buffer, "%s%s = clamp(%s%s + (%s - vec4(0.5))%s, 0.0, 1.0);\n",
9593 dstreg, dstmask, arg1, dstmask, arg2, dstmask);
9594 break;
9595
9597 shader_addline(buffer, "%s%s = clamp((%s%s + (%s - vec4(0.5))%s) * 2.0, 0.0, 1.0);\n",
9598 dstreg, dstmask, arg1, dstmask, arg2, dstmask);
9599 break;
9600
9602 shader_addline(buffer, "%s%s = clamp(%s%s - %s%s, 0.0, 1.0);\n",
9603 dstreg, dstmask, arg1, dstmask, arg2, dstmask);
9604 break;
9605
9607 shader_addline(buffer, "%s%s = clamp((vec4(1.0) - %s)%s * %s%s + %s%s, 0.0, 1.0);\n",
9608 dstreg, dstmask, arg1, dstmask, arg2, dstmask, arg1, dstmask);
9609 break;
9610
9613 shader_addline(buffer, "%s%s = mix(%s%s, %s%s, %s.w);\n",
9614 dstreg, dstmask, arg2, dstmask, arg1, dstmask, arg0);
9615 break;
9616
9619 shader_addline(buffer, "%s%s = mix(%s%s, %s%s, %s.w);\n",
9620 dstreg, dstmask, arg2, dstmask, arg1, dstmask, arg0);
9621 break;
9622
9625 shader_addline(buffer, "%s%s = mix(%s%s, %s%s, %s.w);\n",
9626 dstreg, dstmask, arg2, dstmask, arg1, dstmask, arg0);
9627 break;
9628
9631 shader_addline(buffer, "%s%s = clamp(%s%s * (1.0 - %s.w) + %s%s, 0.0, 1.0);\n",
9632 dstreg, dstmask, arg2, dstmask, arg0, arg1, dstmask);
9633 break;
9634
9637 shader_addline(buffer, "%s%s = mix(%s%s, %s%s, %s.w);\n",
9638 dstreg, dstmask, arg2, dstmask, arg1, dstmask, arg0);
9639 break;
9640
9642 shader_addline(buffer, "%s%s = clamp(%s%s * %s.w + %s%s, 0.0, 1.0);\n",
9643 dstreg, dstmask, arg2, dstmask, arg1, arg1, dstmask);
9644 break;
9645
9647 shader_addline(buffer, "%s%s = clamp(%s%s * %s%s + %s.w, 0.0, 1.0);\n",
9648 dstreg, dstmask, arg1, dstmask, arg2, dstmask, arg1);
9649 break;
9650
9652 shader_addline(buffer, "%s%s = clamp(%s%s * (1.0 - %s.w) + %s%s, 0.0, 1.0);\n",
9653 dstreg, dstmask, arg2, dstmask, arg1, arg1, dstmask);
9654 break;
9656 shader_addline(buffer, "%s%s = clamp((vec4(1.0) - %s)%s * %s%s + %s.w, 0.0, 1.0);\n",
9657 dstreg, dstmask, arg1, dstmask, arg2, dstmask, arg1);
9658 break;
9659
9662 /* These are handled in the first pass, nothing to do. */
9663 break;
9664
9666 shader_addline(buffer, "%s%s = vec4(clamp(dot(%s.xyz - 0.5, %s.xyz - 0.5) * 4.0, 0.0, 1.0))%s;\n",
9667 dstreg, dstmask, arg1, arg2, dstmask);
9668 break;
9669
9671 shader_addline(buffer, "%s%s = clamp(%s%s * %s%s + %s%s, 0.0, 1.0);\n",
9672 dstreg, dstmask, arg1, dstmask, arg2, dstmask, arg0, dstmask);
9673 break;
9674
9675 case WINED3D_TOP_LERP:
9676 /* MSDN isn't quite right here. */
9677 shader_addline(buffer, "%s%s = mix(%s%s, %s%s, %s%s);\n",
9678 dstreg, dstmask, arg2, dstmask, arg1, dstmask, arg0, dstmask);
9679 break;
9680
9681 default:
9682 FIXME("Unhandled operation %#x.\n", op);
9683 break;
9684 }
9685}
GLclampf GLclampf GLclampf alpha
Definition: gl.h:1740
GLuint GLuint GLuint GLuint arg1
Definition: glext.h:9513
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
static const char * shader_glsl_get_ffp_fragment_op_arg(struct wined3d_string_buffer *buffer, unsigned int argnum, unsigned int stage, DWORD arg)
Definition: glsl_shader.c:9448
#define WINED3DTA_TFACTOR
Definition: wined3d.h:884
#define WINED3DTA_CURRENT
Definition: wined3d.h:882
@ WINED3D_TOP_SELECT_ARG1
Definition: wined3d.h:629
@ WINED3D_TOP_DISABLE
Definition: wined3d.h:628
@ WINED3D_TOP_BLEND_DIFFUSE_ALPHA
Definition: wined3d.h:639
@ WINED3D_TOP_ADD
Definition: wined3d.h:634
@ WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM
Definition: wined3d.h:642
@ WINED3D_TOP_BLEND_CURRENT_ALPHA
Definition: wined3d.h:643
@ WINED3D_TOP_ADD_SIGNED_2X
Definition: wined3d.h:636
@ WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA
Definition: wined3d.h:648
@ WINED3D_TOP_MULTIPLY_ADD
Definition: wined3d.h:652
@ WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR
Definition: wined3d.h:647
@ WINED3D_TOP_SUBTRACT
Definition: wined3d.h:637
@ WINED3D_TOP_BUMPENVMAP_LUMINANCE
Definition: wined3d.h:650
@ WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA
Definition: wined3d.h:646
@ WINED3D_TOP_MODULATE
Definition: wined3d.h:631
@ WINED3D_TOP_BUMPENVMAP
Definition: wined3d.h:649
@ WINED3D_TOP_MODULATE_4X
Definition: wined3d.h:633
@ WINED3D_TOP_SELECT_ARG2
Definition: wined3d.h:630
@ WINED3D_TOP_LERP
Definition: wined3d.h:653
@ WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR
Definition: wined3d.h:645
@ WINED3D_TOP_BLEND_TEXTURE_ALPHA
Definition: wined3d.h:640
@ WINED3D_TOP_ADD_SIGNED
Definition: wined3d.h:635
@ WINED3D_TOP_DOTPRODUCT3
Definition: wined3d.h:651
@ WINED3D_TOP_ADD_SMOOTH
Definition: wined3d.h:638
@ WINED3D_TOP_MODULATE_2X
Definition: wined3d.h:632
@ WINED3D_TOP_BLEND_FACTOR_ALPHA
Definition: wined3d.h:641
#define WINED3DTA_DIFFUSE
Definition: wined3d.h:881
#define WINED3DTA_TEXTURE
Definition: wined3d.h:883

Referenced by shader_glsl_generate_ffp_fragment_shader().

◆ shader_glsl_ffp_mcs()

static const char * shader_glsl_ffp_mcs ( enum wined3d_material_color_source  mcs,
const char *  material 
)
static

Definition at line 8985 of file glsl_shader.c.

8986{
8987 switch (mcs)
8988 {
8990 return material;
8991 case WINED3D_MCS_COLOR1:
8992 return "ffp_attrib_diffuse";
8993 case WINED3D_MCS_COLOR2:
8994 return "ffp_attrib_specular";
8995 default:
8996 ERR("Invalid material color source %#x.\n", mcs);
8997 return "<invalid>";
8998 }
8999}
static struct myctx * mcs
Definition: adnstest.c:53
@ WINED3D_MCS_COLOR2
Definition: wined3d.h:523
@ WINED3D_MCS_MATERIAL
Definition: wined3d.h:521
@ WINED3D_MCS_COLOR1
Definition: wined3d.h:522

Referenced by shader_glsl_ffp_vertex_lighting().

◆ shader_glsl_ffp_vertex_light_uniform()

static void shader_glsl_ffp_vertex_light_uniform ( const struct wined3d_context_gl *  context_gl,
const struct wined3d_state *  state,
unsigned int  light,
enum wined3d_light_type  type,
const struct wined3d_light_constants *  constants,
struct glsl_shader_prog_link *  prog 
)
static

Definition at line 1610 of file glsl_shader.c.

1613{
1614 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1615
1616 GL_EXTCALL(glUniform4fv(prog->vs.light_location[light].diffuse, 1, &constants->diffuse.r));
1617 GL_EXTCALL(glUniform4fv(prog->vs.light_location[light].specular, 1, &constants->specular.r));
1618 GL_EXTCALL(glUniform4fv(prog->vs.light_location[light].ambient, 1, &constants->ambient.r));
1619
1620 switch (type)
1621 {
1623 GL_EXTCALL(glUniform4fv(prog->vs.light_location[light].position, 1, &constants->position.x));
1624 GL_EXTCALL(glUniform1f(prog->vs.light_location[light].range, constants->range));
1625 GL_EXTCALL(glUniform1f(prog->vs.light_location[light].c_att, constants->const_att));
1626 GL_EXTCALL(glUniform1f(prog->vs.light_location[light].l_att, constants->linear_att));
1627 GL_EXTCALL(glUniform1f(prog->vs.light_location[light].q_att, constants->quad_att));
1628 break;
1629
1630 case WINED3D_LIGHT_SPOT:
1631 GL_EXTCALL(glUniform4fv(prog->vs.light_location[light].position, 1, &constants->position.x));
1632
1633 GL_EXTCALL(glUniform3fv(prog->vs.light_location[light].direction, 1, &constants->direction.x));
1634
1635 GL_EXTCALL(glUniform1f(prog->vs.light_location[light].range, constants->range));
1636 GL_EXTCALL(glUniform1f(prog->vs.light_location[light].falloff, constants->falloff));
1637 GL_EXTCALL(glUniform1f(prog->vs.light_location[light].c_att, constants->const_att));
1638 GL_EXTCALL(glUniform1f(prog->vs.light_location[light].l_att, constants->linear_att));
1639 GL_EXTCALL(glUniform1f(prog->vs.light_location[light].q_att, constants->quad_att));
1640 GL_EXTCALL(glUniform1f(prog->vs.light_location[light].cos_htheta, constants->cos_half_theta));
1641 GL_EXTCALL(glUniform1f(prog->vs.light_location[light].cos_hphi, constants->cos_half_phi));
1642 break;
1643
1645 GL_EXTCALL(glUniform3fv(prog->vs.light_location[light].direction, 1, &constants->direction.x));
1646 break;
1647
1649 GL_EXTCALL(glUniform4fv(prog->vs.light_location[light].position, 1, &constants->position.x));
1650 break;
1651
1652 default:
1653 FIXME("Unrecognized light type %#x.\n", type);
1654 }
1655 checkGLcall("setting FFP lights uniforms");
1656}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum light
Definition: glfuncs.h:170
@ WINED3D_LIGHT_SPOT
Definition: wined3d.h:67
@ WINED3D_LIGHT_PARALLELPOINT
Definition: wined3d.h:69
@ WINED3D_LIGHT_POINT
Definition: wined3d.h:66
@ WINED3D_LIGHT_DIRECTIONAL
Definition: wined3d.h:68

Referenced by shader_glsl_load_constants().

◆ shader_glsl_ffp_vertex_lighting()

static void shader_glsl_ffp_vertex_lighting ( struct wined3d_string_buffer *  buffer,
const struct wined3d_ffp_vs_settings *  settings,
BOOL  legacy_lighting 
)
static

Definition at line 9016 of file glsl_shader.c.

9018{
9019 const char *diffuse, *specular, *emissive, *ambient;
9020 unsigned int i, idx;
9021
9022 if (!settings->lighting)
9023 {
9024 if (settings->diffuse)
9025 shader_addline(buffer, "ffp_varying_diffuse = ffp_attrib_diffuse;\n");
9026 else
9027 shader_addline(buffer, "ffp_varying_diffuse = vec4(1.0);\n");
9028 shader_addline(buffer, "ffp_varying_specular = ffp_attrib_specular;\n");
9029 return;
9030 }
9031
9032 shader_addline(buffer, "vec3 ambient = ffp_light_ambient;\n");
9033 shader_addline(buffer, "vec3 diffuse = vec3(0.0);\n");
9034 shader_addline(buffer, "vec3 dir, dst;\n");
9035 shader_addline(buffer, "float att, t;\n");
9036
9037 if (settings->specular_enable)
9038 shader_addline(buffer, "vec4 specular = vec4(0.0);\n");
9039
9040 ambient = shader_glsl_ffp_mcs(settings->ambient_source, "ffp_material.ambient");
9041 diffuse = shader_glsl_ffp_mcs(settings->diffuse_source, "ffp_material.diffuse");
9042 specular = shader_glsl_ffp_mcs(settings->specular_source, "ffp_material.specular");
9043 emissive = shader_glsl_ffp_mcs(settings->emissive_source, "ffp_material.emissive");
9044
9045 idx = 0;
9046 for (i = 0; i < settings->point_light_count; ++i, ++idx)
9047 {
9048 shader_addline(buffer, "dir = ffp_light[%u].position.xyz - ec_pos.xyz;\n", idx);
9049 shader_addline(buffer, "dst.z = dot(dir, dir);\n");
9050 shader_addline(buffer, "dst.y = sqrt(dst.z);\n");
9051 shader_addline(buffer, "dst.x = 1.0;\n");
9052 if (legacy_lighting)
9053 {
9054 shader_addline(buffer, "dst.y = (ffp_light[%u].range - dst.y) / ffp_light[%u].range;\n", idx, idx);
9055 shader_addline(buffer, "dst.z = dst.y * dst.y;\n");
9056 shader_addline(buffer, "if (dst.y > 0.0)\n{\n");
9057 }
9058 else
9059 {
9060 shader_addline(buffer, "if (dst.y <= ffp_light[%u].range)\n{\n", idx);
9061 }
9062 shader_addline(buffer, "att = dot(dst.xyz, vec3(ffp_light[%u].c_att,"
9063 " ffp_light[%u].l_att, ffp_light[%u].q_att));\n", idx, idx, idx);
9064 if (!legacy_lighting)
9065 shader_addline(buffer, "att = 1.0 / att;\n");
9066 shader_addline(buffer, "ambient += ffp_light[%u].ambient.xyz * att;\n", idx);
9067 if (!settings->normal)
9068 {
9069 shader_addline(buffer, "}\n");
9070 continue;
9071 }
9072 shader_addline(buffer, "dir = ffp_normalize(dir);\n");
9074 shader_addline(buffer, "}\n");
9075 }
9076
9077 for (i = 0; i < settings->spot_light_count; ++i, ++idx)
9078 {
9079 shader_addline(buffer, "dir = ffp_light[%u].position.xyz - ec_pos.xyz;\n", idx);
9080 shader_addline(buffer, "dst.z = dot(dir, dir);\n");
9081 shader_addline(buffer, "dst.y = sqrt(dst.z);\n");
9082 shader_addline(buffer, "dst.x = 1.0;\n");
9083 if (legacy_lighting)
9084 {
9085 shader_addline(buffer, "dst.y = (ffp_light[%u].range - dst.y) / ffp_light[%u].range;\n", idx, idx);
9086 shader_addline(buffer, "dst.z = dst.y * dst.y;\n");
9087 shader_addline(buffer, "if (dst.y > 0.0)\n{\n");
9088 }
9089 else
9090 {
9091 shader_addline(buffer, "if (dst.y <= ffp_light[%u].range)\n{\n", idx);
9092 }
9093 shader_addline(buffer, "dir = ffp_normalize(dir);\n");
9094 shader_addline(buffer, "t = dot(-dir, ffp_normalize(ffp_light[%u].direction));\n", idx);
9095 shader_addline(buffer, "if (t > ffp_light[%u].cos_htheta) att = 1.0;\n", idx);
9096 shader_addline(buffer, "else if (t <= ffp_light[%u].cos_hphi) att = 0.0;\n", idx);
9097 shader_addline(buffer, "else att = pow((t - ffp_light[%u].cos_hphi)"
9098 " / (ffp_light[%u].cos_htheta - ffp_light[%u].cos_hphi), ffp_light[%u].falloff);\n",
9099 idx, idx, idx, idx);
9100 if (legacy_lighting)
9101 shader_addline(buffer, "att *= dot(dst.xyz, vec3(ffp_light[%u].c_att,"
9102 " ffp_light[%u].l_att, ffp_light[%u].q_att));\n",
9103 idx, idx, idx);
9104 else
9105 shader_addline(buffer, "att /= dot(dst.xyz, vec3(ffp_light[%u].c_att,"
9106 " ffp_light[%u].l_att, ffp_light[%u].q_att));\n",
9107 idx, idx, idx);
9108 shader_addline(buffer, "ambient += ffp_light[%u].ambient.xyz * att;\n", idx);
9109 if (!settings->normal)
9110 {
9111 shader_addline(buffer, "}\n");
9112 continue;
9113 }
9115 shader_addline(buffer, "}\n");
9116 }
9117
9118 for (i = 0; i < settings->directional_light_count; ++i, ++idx)
9119 {
9120 shader_addline(buffer, "ambient += ffp_light[%u].ambient.xyz;\n", idx);
9121 if (!settings->normal)
9122 continue;
9123 shader_addline(buffer, "att = 1.0;\n");
9124 shader_addline(buffer, "dir = ffp_normalize(ffp_light[%u].direction.xyz);\n", idx);
9126 }
9127
9128 for (i = 0; i < settings->parallel_point_light_count; ++i, ++idx)
9129 {
9130 shader_addline(buffer, "ambient += ffp_light[%u].ambient.xyz;\n", idx);
9131 if (!settings->normal)
9132 continue;
9133 shader_addline(buffer, "att = 1.0;\n");
9134 shader_addline(buffer, "dir = ffp_normalize(ffp_light[%u].position.xyz);\n", idx);
9136 }
9137
9138 shader_addline(buffer, "ffp_varying_diffuse.xyz = %s.xyz * ambient + %s.xyz * diffuse + %s.xyz;\n",
9139 ambient, diffuse, emissive);
9140 shader_addline(buffer, "ffp_varying_diffuse.w = %s.w;\n", diffuse);
9141 if (settings->specular_enable)
9142 shader_addline(buffer, "ffp_varying_specular = %s * specular;\n", specular);
9143 else
9144 shader_addline(buffer, "ffp_varying_specular = ffp_attrib_specular;\n");
9145}
static const char * shader_glsl_ffp_mcs(enum wined3d_material_color_source mcs, const char *material)
Definition: glsl_shader.c:8985
static void shader_glsl_ffp_vertex_lighting_footer(struct wined3d_string_buffer *buffer, const struct wined3d_ffp_vs_settings *settings, unsigned int idx, BOOL legacy_lighting)
Definition: glsl_shader.c:9001
float specular[3]
Definition: d3drm.c:3534
float emissive[3]
Definition: d3drm.c:3535

Referenced by shader_glsl_generate_ffp_vertex_shader().

◆ shader_glsl_ffp_vertex_lighting_footer()

static void shader_glsl_ffp_vertex_lighting_footer ( struct wined3d_string_buffer *  buffer,
const struct wined3d_ffp_vs_settings *  settings,
unsigned int  idx,
BOOL  legacy_lighting 
)
static

Definition at line 9001 of file glsl_shader.c.

9003{
9004 shader_addline(buffer, "diffuse += clamp(dot(dir, normal), 0.0, 1.0)"
9005 " * ffp_light[%u].diffuse.xyz * att;\n", idx);
9006 if (settings->localviewer)
9007 shader_addline(buffer, "t = dot(normal, ffp_normalize(dir - ffp_normalize(ec_pos.xyz)));\n");
9008 else
9009 shader_addline(buffer, "t = dot(normal, ffp_normalize(dir + vec3(0.0, 0.0, -1.0)));\n");
9010 if (settings->specular_enable)
9011 shader_addline(buffer, "if (dot(dir, normal) > 0.0 && t > 0.0%s) specular +="
9012 " pow(t, ffp_material.shininess) * ffp_light[%u].specular * att;\n",
9013 legacy_lighting ? " && ffp_material.shininess > 0.0" : "", idx);
9014}

Referenced by shader_glsl_ffp_vertex_lighting().

◆ shader_glsl_ffp_vertex_material_uniform()

static void shader_glsl_ffp_vertex_material_uniform ( struct wined3d_context_gl *  context_gl,
const struct wined3d_state *  state,
struct glsl_shader_prog_link *  prog 
)
static

Definition at line 1593 of file glsl_shader.c.

1595{
1596 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1597 const struct wined3d_ffp_vs_constants *constants;
1598
1600 context_gl->c.device->push_constants[WINED3D_PUSH_CONSTANTS_VS_FFP], &context_gl->c);
1601
1602 GL_EXTCALL(glUniform4fv(prog->vs.material_specular_location, 1, &constants->material.specular.r));
1603 GL_EXTCALL(glUniform1f(prog->vs.material_shininess_location, constants->material.power));
1604 GL_EXTCALL(glUniform4fv(prog->vs.material_ambient_location, 1, &constants->material.ambient.r));
1605 GL_EXTCALL(glUniform4fv(prog->vs.material_diffuse_location, 1, &constants->material.diffuse.r));
1606 GL_EXTCALL(glUniform4fv(prog->vs.material_emissive_location, 1, &constants->material.emissive.r));
1607 checkGLcall("setting FFP material uniforms");
1608}
@ WINED3D_PUSH_CONSTANTS_VS_FFP

Referenced by shader_glsl_load_constants().

◆ shader_glsl_ffp_vertex_normalmatrix_uniform()

static void shader_glsl_ffp_vertex_normalmatrix_uniform ( const struct wined3d_context_gl *  context_gl,
const struct wined3d_ffp_vs_constants *  constants,
struct glsl_shader_prog_link *  prog 
)
static

Definition at line 1565 of file glsl_shader.c.

1567{
1568 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1569
1570 if (prog->vs.normal_matrix_location == -1)
1571 return;
1572
1573 GL_EXTCALL(glUniformMatrix4fv(prog->vs.normal_matrix_location,
1574 1, FALSE, &constants->modelview.not_blended.normal_matrix._11));
1575 checkGLcall("glUniformMatrix4fv");
1576}

Referenced by shader_glsl_load_constants().

◆ shader_glsl_ffp_vertex_texmatrix_uniform()

static void shader_glsl_ffp_vertex_texmatrix_uniform ( const struct wined3d_context_gl *  context_gl,
const struct wined3d_ffp_vs_constants *  constants,
unsigned int  tex,
struct glsl_shader_prog_link *  prog 
)
static

Definition at line 1578 of file glsl_shader.c.

1580{
1581 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1582
1583 if (tex >= WINED3D_MAX_FFP_TEXTURES)
1584 return;
1585 if (prog->vs.texture_matrix_location[tex] == -1)
1586 return;
1587
1588 GL_EXTCALL(glUniformMatrix4fv(prog->vs.texture_matrix_location[tex],
1589 1, FALSE, &constants->texture_matrices[tex]._11));
1590 checkGLcall("glUniformMatrix4fv");
1591}

Referenced by shader_glsl_load_constants().

◆ shader_glsl_find_ffp_fragment_shader()

static struct glsl_ffp_fragment_shader * shader_glsl_find_ffp_fragment_shader ( struct shader_glsl_priv *  priv,
const struct ffp_frag_settings *  args,
const struct wined3d_context_gl *  context_gl 
)
static

Definition at line 10105 of file glsl_shader.c.

10107{
10108 struct glsl_ffp_fragment_shader *glsl_desc;
10109 const struct ffp_frag_desc *desc;
10110
10113
10114 if (!(glsl_desc = malloc(sizeof(*glsl_desc))))
10115 return NULL;
10116
10117 glsl_desc->entry.settings = *args;
10118 glsl_desc->id = shader_glsl_generate_ffp_fragment_shader(priv, args, context_gl);
10119 list_init(&glsl_desc->linked_programs);
10120 add_ffp_frag_shader(&priv->ffp_fragment_shaders, &glsl_desc->entry);
10121
10122 return glsl_desc;
10123}
static void list_init(struct list_entry *head)
Definition: list.h:51
const struct ffp_frag_desc * find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders, const struct ffp_frag_settings *settings)
Definition: utils.c:6419
void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc)
Definition: utils.c:6426
static GLuint shader_glsl_generate_ffp_fragment_shader(struct shader_glsl_priv *priv, const struct ffp_frag_settings *settings, const struct wined3d_context_gl *context_gl)
Definition: glsl_shader.c:9688
struct ffp_frag_desc entry
Definition: glsl_shader.c:340

Referenced by set_glsl_shader_program().

◆ shader_glsl_find_ffp_vertex_shader()

static struct glsl_ffp_vertex_shader * shader_glsl_find_ffp_vertex_shader ( struct shader_glsl_priv *  priv,
const struct wined3d_gl_info *  gl_info,
const struct wined3d_ffp_vs_settings *  settings 
)
static

Definition at line 10084 of file glsl_shader.c.

10086{
10088 const struct wine_rb_entry *entry;
10089
10092
10093 if (!(shader = malloc(sizeof(*shader))))
10094 return NULL;
10095
10096 shader->desc.settings = *settings;
10098 list_init(&shader->linked_programs);
10099 if (wine_rb_put(&priv->ffp_vertex_shaders, &shader->desc.settings, &shader->desc.entry) == -1)
10100 ERR("Failed to insert ffp vertex shader.\n");
10101
10102 return shader;
10103}
static GLuint shader_glsl_generate_ffp_vertex_shader(struct shader_glsl_priv *priv, const struct wined3d_ffp_vs_settings *settings, const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:9148

Referenced by set_glsl_shader_program().

◆ shader_glsl_find_sampler()

static unsigned int shader_glsl_find_sampler ( const struct wined3d_shader_sampler_map *  sampler_map,
unsigned int  resource_idx,
unsigned int  sampler_idx 
)
static

Definition at line 5500 of file glsl_shader.c.

5502{
5503 struct wined3d_shader_sampler_map_entry *entries = sampler_map->entries;
5504 unsigned int i;
5505
5506 for (i = 0; i < sampler_map->count; ++i)
5507 {
5508 if (entries[i].resource_idx == resource_idx && entries[i].sampler_idx == sampler_idx)
5509 return entries[i].bind_idx;
5510 }
5511
5512 ERR("No GLSL sampler found for resource %u / sampler %u.\n", resource_idx, sampler_idx);
5513
5514 return ~0u;
5515}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
unsigned int sampler_idx
struct wined3d_shader_sampler_map_entry * entries

Referenced by shader_glsl_bufinfo(), shader_glsl_gather4(), shader_glsl_ld(), shader_glsl_ld_raw_structured(), shader_glsl_resinfo(), shader_glsl_sample(), shader_glsl_sample_c(), and shader_glsl_sample_info().

◆ shader_glsl_fixup_position()

static void shader_glsl_fixup_position ( struct wined3d_string_buffer *  buffer,
BOOL  use_viewport_index 
)
static

Definition at line 3861 of file glsl_shader.c.

3862{
3863 /* Write the final position.
3864 *
3865 * OpenGL coordinates specify the center of the pixel while D3D coords
3866 * specify the corner. The offsets are stored in z and w in
3867 * pos_fixup. pos_fixup.y contains 1.0 or -1.0 to turn the rendering
3868 * upside down for offscreen rendering. pos_fixup.x contains 1.0 to allow
3869 * a MAD. */
3870 if (use_viewport_index)
3871 {
3872 shader_addline(buffer, "gl_Position.y = gl_Position.y * pos_fixup[gl_ViewportIndex].y;\n");
3873 shader_addline(buffer, "gl_Position.xy += pos_fixup[gl_ViewportIndex].zw * gl_Position.ww;\n");
3874 }
3875 else
3876 {
3877 shader_addline(buffer, "gl_Position.y = gl_Position.y * pos_fixup.y;\n");
3878 shader_addline(buffer, "gl_Position.xy += pos_fixup.zw * gl_Position.ww;\n");
3879 }
3880
3881 /* Z coord [0;1]->[-1;1] mapping, see comment in get_projection_matrix()
3882 * in utils.c
3883 *
3884 * Basically we want (in homogeneous coordinates) z = z * 2 - 1. However,
3885 * shaders are run before the homogeneous divide, so we have to take the w
3886 * into account: z = ((z / w) * 2 - 1) * w, which is the same as
3887 * z = z * 2 - w. */
3888 shader_addline(buffer, "gl_Position.z = gl_Position.z * 2.0 - gl_Position.w;\n");
3889}

Referenced by shader_glsl_emit(), shader_glsl_generate_ds_epilogue(), shader_glsl_generate_geometry_shader(), and shader_glsl_generate_vs_epilogue().

◆ shader_glsl_fixup_scalar_register_variable()

static void shader_glsl_fixup_scalar_register_variable ( struct wined3d_string_buffer *  register_name,
const char *  glsl_variable,
const struct wined3d_gl_info *  gl_info 
)
static

Definition at line 2845 of file glsl_shader.c.

2847{
2848 /* The ARB_shading_language_420pack extension allows swizzle operations on
2849 * scalars. */
2851 string_buffer_sprintf(register_name, "%s", glsl_variable);
2852 else
2853 string_buffer_sprintf(register_name, "ivec2(%s, 0)", glsl_variable);
2854}

Referenced by shader_glsl_get_register_name().

◆ shader_glsl_float16()

static void shader_glsl_float16 ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4280 of file glsl_shader.c.

4281{
4283 struct glsl_src_param src;
4284 DWORD write_mask;
4285 const char *fmt;
4286 unsigned int i;
4287
4289 ? "unpackHalf2x16(%s).x);\n" : "packHalf2x16(vec2(%s, 0.0)));\n";
4290
4291 dst = ins->dst[0];
4292 for (i = 0; i < 4; ++i)
4293 {
4294 dst.write_mask = ins->dst[0].write_mask & (WINED3DSP_WRITEMASK_0 << i);
4295 if (!(write_mask = shader_glsl_append_dst_ext(ins->ctx->buffer, ins,
4296 &dst, 0, dst.reg.data_type)))
4297 continue;
4298
4299 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src);
4300 shader_addline(ins->ctx->buffer, fmt, src.param_str);
4301 }
4302}
Definition: dsound.c:943
@ WINED3DSIH_F16TOF32

◆ shader_glsl_free()

static void shader_glsl_free ( struct wined3d_device *  device,
struct wined3d_context *  context 
)
static

Definition at line 11297 of file glsl_shader.c.

11298{
11299 struct shader_glsl_priv *priv = device->shader_priv;
11300
11302 constant_free(&priv->pconst_heap);
11303 constant_free(&priv->vconst_heap);
11304 free(priv->stack);
11307 priv->fragment_pipe->free_private(device, context);
11308 priv->vertex_pipe->vp_free(device, context);
11309
11310 free(device->shader_priv);
11311 device->shader_priv = NULL;
11312}

◆ shader_glsl_free_context_data()

static void shader_glsl_free_context_data ( struct wined3d_context *  context)
static

Definition at line 11325 of file glsl_shader.c.

11326{
11327 free(context->shader_backend_data);
11328}

◆ shader_glsl_free_ffp_fragment_shader()

static void shader_glsl_free_ffp_fragment_shader ( struct wine_rb_entry *  entry,
void *  param 
)
static

Definition at line 12050 of file glsl_shader.c.

12051{
12053 struct glsl_ffp_fragment_shader, entry.entry);
12054 struct glsl_shader_prog_link *program, *program2;
12055 struct glsl_ffp_destroy_ctx *ctx = param;
12056 const struct wined3d_gl_info *gl_info;
12057
12058 gl_info = ctx->context_gl->gl_info;
12059 LIST_FOR_EACH_ENTRY_SAFE(program, program2, &shader->linked_programs,
12060 struct glsl_shader_prog_link, ps.shader_entry)
12061 {
12062 delete_glsl_program_entry(ctx->priv, gl_info, program);
12063 }
12064 GL_EXTCALL(glDeleteShader(shader->id));
12065 free(shader);
12066}
GLfloat param
Definition: glext.h:5796

Referenced by glsl_fragment_pipe_free().

◆ shader_glsl_free_ffp_vertex_shader()

static void shader_glsl_free_ffp_vertex_shader ( struct wine_rb_entry *  entry,
void *  param 
)
static

Definition at line 11762 of file glsl_shader.c.

11763{
11765 struct glsl_ffp_vertex_shader, desc.entry);
11766 struct glsl_shader_prog_link *program, *program2;
11767 struct glsl_ffp_destroy_ctx *ctx = param;
11768 const struct wined3d_gl_info *gl_info;
11769
11770 gl_info = ctx->context_gl->gl_info;
11771 LIST_FOR_EACH_ENTRY_SAFE(program, program2, &shader->linked_programs,
11772 struct glsl_shader_prog_link, vs.shader_entry)
11773 {
11774 delete_glsl_program_entry(ctx->priv, gl_info, program);
11775 }
11776 GL_EXTCALL(glDeleteShader(shader->id));
11777 free(shader);
11778}

Referenced by glsl_vertex_pipe_vp_free().

◆ shader_glsl_full_ffp_varyings()

static unsigned int shader_glsl_full_ffp_varyings ( const struct wined3d_gl_info *  gl_info)
static

Definition at line 416 of file glsl_shader.c.

417{
418 /* On core profile we have to also count diffuse and specular colours and
419 * the fog coordinate. */
420 return gl_info->limits.glsl_varyings >= (gl_info->supported[WINED3D_GL_LEGACY_CONTEXT]
422}

Referenced by glsl_fragment_pipe_vdecl(), glsl_fragment_pipe_vs(), shader_glsl_generate_ffp_vertex_shader(), shader_glsl_generate_vs3_rasterizer_input_setup(), and shader_glsl_get_caps().

◆ shader_glsl_gather4()

static void shader_glsl_gather4 ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 6373 of file glsl_shader.c.

6374{
6375 unsigned int resource_param_idx, resource_idx, sampler_idx, sampler_bind_idx, component_idx;
6376 const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps;
6377 const char *prefix = shader_glsl_get_prefix(reg_maps->shader_version.type);
6378 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
6379 struct glsl_src_param coord_param, compare_param, offset_param;
6380 const struct wined3d_gl_info *gl_info = priv->gl_info;
6381 const struct wined3d_shader_resource_info *resource_info;
6382 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
6383 unsigned int coord_size, offset_size;
6384 char dst_swizzle[6];
6385 BOOL has_offset;
6386
6387 if (!gl_info->supported[ARB_TEXTURE_GATHER])
6388 {
6389 FIXME("OpenGL implementation does not support textureGather.\n");
6390 return;
6391 }
6392
6393 has_offset = ins->handler_idx == WINED3DSIH_GATHER4_PO
6396
6397 resource_param_idx =
6399 resource_idx = ins->src[resource_param_idx].reg.idx[0].offset;
6400 sampler_idx = ins->src[resource_param_idx + 1].reg.idx[0].offset;
6401 component_idx = shader_glsl_swizzle_get_component(ins->src[resource_param_idx + 1].swizzle, 0);
6402 sampler_bind_idx = shader_glsl_find_sampler(&reg_maps->sampler_map, resource_idx, sampler_idx);
6403
6404 if (!(resource_info = shader_glsl_get_resource_info(ins, &ins->src[resource_param_idx].reg)))
6405 return;
6406
6407 if (resource_info->type >= ARRAY_SIZE(resource_type_info))
6408 {
6409 ERR("Unexpected resource type %#x.\n", resource_info->type);
6410 return;
6411 }
6412 shader_glsl_get_coord_size(resource_info->type, &coord_size, &offset_size);
6413
6414 shader_glsl_swizzle_to_str(ins->src[resource_param_idx].swizzle, FALSE, ins->dst[0].write_mask, dst_swizzle);
6415 shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, resource_info->data_type);
6416
6417 shader_glsl_add_src_param(ins, &ins->src[0], wined3d_mask_from_size(coord_size), &coord_param);
6418
6419 shader_addline(buffer, "textureGather%s(%s_sampler%u, %s",
6420 has_offset ? "Offset" : "", prefix, sampler_bind_idx, coord_param.param_str);
6422 {
6423 shader_glsl_add_src_param(ins, &ins->src[resource_param_idx + 2], WINED3DSP_WRITEMASK_0, &compare_param);
6424 shader_addline(buffer, ", %s", compare_param.param_str);
6425 }
6427 {
6428 shader_glsl_add_src_param(ins, &ins->src[1], wined3d_mask_from_size(offset_size), &offset_param);
6429 shader_addline(buffer, ", %s", offset_param.param_str);
6430 }
6431 else if (has_offset)
6432 {
6433 int offset_immdata[4] = {ins->texel_offset.u, ins->texel_offset.v, ins->texel_offset.w};
6434 shader_addline(buffer, ", ");
6435 shader_glsl_append_imm_ivec(buffer, offset_immdata, offset_size);
6436 }
6437 if (component_idx)
6438 shader_addline(buffer, ", %u", component_idx);
6439
6440 shader_addline(buffer, ")%s);\n", dst_swizzle);
6441}
static void shader_glsl_get_coord_size(enum wined3d_shader_resource_type resource_type, unsigned int *coord_size, unsigned int *deriv_size)
Definition: glsl_shader.c:3598
struct wined3d_shader_texel_offset texel_offset
enum wined3d_shader_resource_type type
enum wined3d_data_type data_type
@ WINED3DSIH_GATHER4_PO_C
@ WINED3DSIH_GATHER4_C
@ WINED3DSIH_GATHER4_PO
static BOOL wined3d_shader_instruction_has_texel_offset(const struct wined3d_shader_instruction *ins)

◆ shader_glsl_gen_modifier()

static void shader_glsl_gen_modifier ( enum wined3d_shader_src_modifier  src_modifier,
const char *  in_reg,
const char *  in_regswizzle,
char *  out_str 
)
static

Definition at line 2796 of file glsl_shader.c.

2798{
2799 switch (src_modifier)
2800 {
2801 case WINED3DSPSM_DZ: /* Need to handle this in the instructions itself (texld & texcrd). */
2802 case WINED3DSPSM_DW:
2803 case WINED3DSPSM_NONE:
2804 sprintf(out_str, "%s%s", in_reg, in_regswizzle);
2805 break;
2806 case WINED3DSPSM_NEG:
2807 sprintf(out_str, "-%s%s", in_reg, in_regswizzle);
2808 break;
2809 case WINED3DSPSM_NOT:
2810 sprintf(out_str, "!%s%s", in_reg, in_regswizzle);
2811 break;
2812 case WINED3DSPSM_BIAS:
2813 sprintf(out_str, "(%s%s - vec4(0.5)%s)", in_reg, in_regswizzle, in_regswizzle);
2814 break;
2816 sprintf(out_str, "-(%s%s - vec4(0.5)%s)", in_reg, in_regswizzle, in_regswizzle);
2817 break;
2818 case WINED3DSPSM_SIGN:
2819 sprintf(out_str, "(2.0 * (%s%s - 0.5))", in_reg, in_regswizzle);
2820 break;
2822 sprintf(out_str, "-(2.0 * (%s%s - 0.5))", in_reg, in_regswizzle);
2823 break;
2824 case WINED3DSPSM_COMP:
2825 sprintf(out_str, "(1.0 - %s%s)", in_reg, in_regswizzle);
2826 break;
2827 case WINED3DSPSM_X2:
2828 sprintf(out_str, "(2.0 * %s%s)", in_reg, in_regswizzle);
2829 break;
2830 case WINED3DSPSM_X2NEG:
2831 sprintf(out_str, "-(2.0 * %s%s)", in_reg, in_regswizzle);
2832 break;
2833 case WINED3DSPSM_ABS:
2834 sprintf(out_str, "abs(%s%s)", in_reg, in_regswizzle);
2835 break;
2836 case WINED3DSPSM_ABSNEG:
2837 sprintf(out_str, "-abs(%s%s)", in_reg, in_regswizzle);
2838 break;
2839 default:
2840 FIXME("Unhandled modifier %u\n", src_modifier);
2841 sprintf(out_str, "%s%s", in_reg, in_regswizzle);
2842 }
2843}
@ WINED3DSPSM_ABSNEG
@ WINED3DSPSM_X2NEG
@ WINED3DSPSM_BIAS
@ WINED3DSPSM_BIASNEG
@ WINED3DSPSM_COMP
@ WINED3DSPSM_ABS
@ WINED3DSPSM_NOT
@ WINED3DSPSM_SIGNNEG
@ WINED3DSPSM_DW
@ WINED3DSPSM_X2
@ WINED3DSPSM_SIGN
@ WINED3DSPSM_NONE
@ WINED3DSPSM_NEG
@ WINED3DSPSM_DZ

Referenced by shader_glsl_add_src_param_ext().

◆ shader_glsl_gen_sample_c_lz_emulation()

static void shader_glsl_gen_sample_c_lz_emulation ( const struct wined3d_shader_instruction *  ins,
unsigned int  sampler_bind_idx,
const struct glsl_sample_function *  sample_function,
unsigned int  coord_size,
const char *  coord_param,
const char *  ref_param 
)
static

Definition at line 6298 of file glsl_shader.c.

6301{
6302 const struct wined3d_shader_version *version = &ins->ctx->reg_maps->shader_version;
6303 unsigned int deriv_size = wined3d_popcount(sample_function->deriv_mask);
6304 const struct wined3d_shader_texel_offset *offset = &ins->texel_offset;
6305 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
6306 char dst_swizzle[6];
6307
6308 WARN("Emitting textureGrad() for sample_c_lz.\n");
6309
6310 shader_glsl_swizzle_to_str(WINED3DSP_NOSWIZZLE, FALSE, ins->dst[0].write_mask, dst_swizzle);
6311 shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, sample_function->data_type);
6312 shader_addline(buffer, "vec4(textureGrad%s(%s_sampler%u, vec%u(%s, %s), vec%u(0.0), vec%u(0.0)",
6313 sample_function->offset_size ? "Offset" : "",
6314 shader_glsl_get_prefix(version->type), sampler_bind_idx,
6315 coord_size, coord_param, ref_param, deriv_size, deriv_size);
6316 if (sample_function->offset_size)
6317 {
6318 int offset_immdata[4] = {offset->u, offset->v, offset->w};
6319 shader_addline(buffer, ", ");
6320 shader_glsl_append_imm_ivec(buffer, offset_immdata, sample_function->offset_size);
6321 }
6322 shader_addline(buffer, "))%s);\n", dst_swizzle);
6323}
enum wined3d_data_type data_type
Definition: glsl_shader.c:99
unsigned int deriv_mask
Definition: glsl_shader.c:98
unsigned int offset_size
Definition: glsl_shader.c:101
#define WINED3DSP_NOSWIZZLE

Referenced by shader_glsl_sample_c().

◆ shader_glsl_generate_alpha_test()

static void shader_glsl_generate_alpha_test ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info,
enum wined3d_cmp_func  alpha_func 
)
static

Definition at line 7679 of file glsl_shader.c.

7681{
7682 /* alpha_func is the PASS condition, not the DISCARD condition. Instead of
7683 * flipping all the operators here, just negate the comparison below. */
7684 static const char * const comparison_operator[] =
7685 {
7686 "", /* WINED3D_CMP_NEVER */
7687 "<", /* WINED3D_CMP_LESS */
7688 "==", /* WINED3D_CMP_EQUAL */
7689 "<=", /* WINED3D_CMP_LESSEQUAL */
7690 ">", /* WINED3D_CMP_GREATER */
7691 "!=", /* WINED3D_CMP_NOTEQUAL */
7692 ">=", /* WINED3D_CMP_GREATEREQUAL */
7693 "" /* WINED3D_CMP_ALWAYS */
7694 };
7695
7696 if (alpha_func == WINED3D_CMP_ALWAYS)
7697 return;
7698
7699 if (alpha_func != WINED3D_CMP_NEVER)
7700 shader_addline(buffer, "if (!(%s[0].a %s alpha_test_ref))\n",
7701 get_fragment_output(gl_info), comparison_operator[alpha_func - WINED3D_CMP_NEVER]);
7702 shader_addline(buffer, " discard;\n");
7703}
@ WINED3D_CMP_ALWAYS
Definition: wined3d.h:468
@ WINED3D_CMP_NEVER
Definition: wined3d.h:461

Referenced by shader_glsl_generate_ffp_fragment_shader(), and shader_glsl_generate_ps_epilogue().

◆ shader_glsl_generate_clip_or_cull_distances()

static void shader_glsl_generate_clip_or_cull_distances ( struct wined3d_string_buffer *  buffer,
const struct wined3d_shader_signature_element *  element,
DWORD  clip_or_cull_distance_mask 
)
static

Definition at line 7225 of file glsl_shader.c.

7227{
7228 unsigned int i, clip_or_cull_index;
7229 const char *name;
7230 char reg_mask[6];
7231
7232 name = element->sysval_semantic == WINED3D_SV_CLIP_DISTANCE ? "Clip" : "Cull";
7233 /* Assign consecutive indices starting from 0. */
7234 clip_or_cull_index = element->semantic_idx ? wined3d_popcount(clip_or_cull_distance_mask & 0xf) : 0;
7235 for (i = 0; i < 4; ++i)
7236 {
7237 if (!(element->mask & (WINED3DSP_WRITEMASK_0 << i)))
7238 continue;
7239
7241 shader_addline(buffer, "gl_%sDistance[%u] = outputs[%u]%s;\n",
7242 name, clip_or_cull_index, element->register_idx, reg_mask);
7243 ++clip_or_cull_index;
7244 }
7245}
Definition: name.c:39
@ WINED3D_SV_CLIP_DISTANCE

Referenced by shader_glsl_setup_sm3_rasterizer_input().

◆ shader_glsl_generate_color_output()

static void shader_glsl_generate_color_output ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info,
const struct wined3d_shader *  shader,
const struct ps_compile_args *  args,
struct wined3d_string_buffer_list *  string_buffers 
)
static

Definition at line 7758 of file glsl_shader.c.

7761{
7762 const struct wined3d_shader_signature *output_signature = &shader->output_signature;
7763 struct wined3d_string_buffer *src, *assignment;
7764 enum wined3d_data_type dst_data_type;
7765 const char *swizzle;
7766 unsigned int i;
7767
7768 if (output_signature->element_count)
7769 {
7770 src = string_buffer_get(string_buffers);
7771 assignment = string_buffer_get(string_buffers);
7772 for (i = 0; i < output_signature->element_count; ++i)
7773 {
7774 const struct wined3d_shader_signature_element *output = &output_signature->elements[i];
7775
7776 /* register_idx is set to ~0u for non-color outputs. */
7777 if (output->register_idx == ~0u)
7778 continue;
7779 if ((unsigned int)output->component_type >= ARRAY_SIZE(component_type_info))
7780 {
7781 FIXME("Unhandled component type %#x.\n", output->component_type);
7782 continue;
7783 }
7784 dst_data_type = component_type_info[output->component_type].data_type;
7785 shader_addline(buffer, "color_out%u = ", output->semantic_idx);
7786 string_buffer_sprintf(src, "ps_out[%u]", output->semantic_idx);
7787 shader_glsl_sprintf_cast(assignment, src->buffer, dst_data_type, WINED3D_DATA_FLOAT, 4);
7788 swizzle = args->rt_alpha_swizzle & (1u << output->semantic_idx) ? ".argb" : "";
7789 shader_addline(buffer, "%s%s;\n", assignment->buffer, swizzle);
7790 }
7791 string_buffer_release(string_buffers, src);
7792 string_buffer_release(string_buffers, assignment);
7793 }
7794 else
7795 {
7796 uint32_t mask = shader->reg_maps.rt_mask;
7797
7798 while (mask)
7799 {
7801 swizzle = args->rt_alpha_swizzle & (1u << i) ? ".argb" : "";
7802 shader_addline(buffer, "color_out%u = ps_out[%u]%s;\n", i, i, swizzle);
7803 }
7804 }
7805}
enum wined3d_component_type component_type

Referenced by shader_glsl_generate_ps_epilogue().

◆ shader_glsl_generate_colour_key_test()

static void shader_glsl_generate_colour_key_test ( struct wined3d_string_buffer *  buffer,
const char *  colour,
const char *  colour_key_low,
const char *  colour_key_high 
)
static

Definition at line 7705 of file glsl_shader.c.

7707{
7708 shader_addline(buffer, "if (all(greaterThanEqual(%s, %s)) && all(lessThan(%s, %s)))\n",
7709 colour, colour_key_low, colour, colour_key_high);
7710 shader_addline(buffer, " discard;\n");
7711}

Referenced by glsl_blitter_generate_p8_shader(), glsl_blitter_generate_plain_shader(), glsl_blitter_generate_yuv_shader(), and shader_glsl_generate_ffp_fragment_shader().

◆ shader_glsl_generate_compute_shader()

static GLuint shader_glsl_generate_compute_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
const struct wined3d_shader *  shader 
)
static

Definition at line 8639 of file glsl_shader.c.

8641{
8642 const struct wined3d_shader_thread_group_size *thread_group_size = &shader->u.cs.thread_group_size;
8643 struct wined3d_string_buffer_list *string_buffers = &priv->string_buffers;
8644 const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
8645 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
8647 struct shader_glsl_ctx_priv priv_ctx;
8648 GLuint shader_id;
8649 unsigned int i;
8650
8651 if (priv->use_vkd3d)
8653
8654 memset(&priv_ctx, 0, sizeof(priv_ctx));
8655 priv_ctx.gl_info = gl_info;
8656 priv_ctx.string_buffers = string_buffers;
8657
8659
8661 shader_addline(buffer, "#extension GL_ARB_compute_shader : enable\n");
8662
8663 shader_generate_glsl_declarations(context_gl, buffer, shader, reg_maps, &priv_ctx);
8664
8665 for (i = 0; i < reg_maps->tgsm_count; ++i)
8666 {
8667 if (reg_maps->tgsm[i].size)
8668 shader_addline(buffer, "shared uint cs_g%u[%u];\n", i, reg_maps->tgsm[i].size);
8669 }
8670
8671 shader_addline(buffer, "layout(local_size_x = %u, local_size_y = %u, local_size_z = %u) in;\n",
8672 thread_group_size->x, thread_group_size->y, thread_group_size->z);
8673
8674 shader_addline(buffer, "void main()\n{\n");
8675 shader_generate_code(shader, buffer, reg_maps, &priv_ctx, NULL, NULL);
8676 shader_addline(buffer, "}\n");
8677
8678 shader_id = GL_EXTCALL(glCreateShader(GL_COMPUTE_SHADER));
8679 TRACE("Compiling shader object %u.\n", shader_id);
8680 shader_glsl_compile(gl_info, shader_id, buffer->buffer);
8681
8682 return shader_id;
8683}
HRESULT shader_generate_code(const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer, const struct wined3d_shader_reg_maps *reg_maps, void *backend_ctx, const DWORD *start, const DWORD *end)
Definition: shader.c:1873
static void shader_generate_glsl_declarations(const struct wined3d_context_gl *context_gl, struct wined3d_string_buffer *buffer, const struct wined3d_shader *shader, const struct wined3d_shader_reg_maps *reg_maps, const struct shader_glsl_ctx_priv *ctx_priv)
Definition: glsl_shader.c:2371
static void shader_glsl_compile(const struct wined3d_gl_info *gl_info, GLuint shader, const char *src)
Definition: glsl_shader.c:537
static void shader_glsl_enable_extensions(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:7713
static GLuint shader_glsl_generate_vkd3d_shader(const struct wined3d_context_gl *context_gl, struct shader_glsl_priv *priv, const struct wined3d_shader *shader, GLenum gl_shader_type)
Definition: glsl_shader.c:707

Referenced by shader_glsl_compile_compute_shader().

◆ shader_glsl_generate_condition()

static void shader_glsl_generate_condition ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5199 of file glsl_shader.c.

5200{
5201 struct glsl_src_param src_param;
5202 const char *condition;
5203
5204 condition = ins->flags == WINED3D_SHADER_CONDITIONAL_OP_NZ ? "bool" : "!bool";
5205 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src_param);
5206 shader_addline(ins->ctx->buffer, "if (%s(%s))\n", condition, src_param.param_str);
5207}
GLenum condition
Definition: glext.h:9255
@ WINED3D_SHADER_CONDITIONAL_OP_NZ

Referenced by shader_glsl_conditional_op(), shader_glsl_if(), and shader_glsl_texkill().

◆ shader_glsl_generate_default_control_point_phase()

static void shader_glsl_generate_default_control_point_phase ( const struct wined3d_shader *  shader,
struct wined3d_string_buffer *  buffer,
const struct wined3d_shader_reg_maps *  reg_maps 
)
static

Definition at line 8265 of file glsl_shader.c.

8267{
8268 const struct wined3d_shader_signature *output_signature = &shader->output_signature;
8269 char reg_mask[6];
8270 unsigned int i;
8271
8272 for (i = 0; i < output_signature->element_count; ++i)
8273 {
8274 const struct wined3d_shader_signature_element *output = &output_signature->elements[i];
8275
8276 shader_glsl_write_mask_to_str(output->mask, reg_mask);
8277 shader_addline(buffer, "shader_out[gl_InvocationID].reg[%u]%s = shader_in[gl_InvocationID].reg[%u]%s;\n",
8278 output->register_idx, reg_mask, output->register_idx, reg_mask);
8279 }
8280}

Referenced by shader_glsl_generate_hull_shader().

◆ shader_glsl_generate_domain_shader()

static GLuint shader_glsl_generate_domain_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
const struct wined3d_shader *  shader,
const struct ds_compile_args *  args 
)
static

Definition at line 8414 of file glsl_shader.c.

8416{
8417 struct wined3d_string_buffer_list *string_buffers = &priv->string_buffers;
8418 const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
8419 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
8421 struct shader_glsl_ctx_priv priv_ctx;
8422 GLuint shader_id;
8423
8424 if (priv->use_vkd3d)
8426
8427 memset(&priv_ctx, 0, sizeof(priv_ctx));
8428 priv_ctx.gl_info = gl_info;
8429 priv_ctx.cur_ds_args = args;
8430 priv_ctx.string_buffers = string_buffers;
8431
8433
8435 shader_addline(buffer, "#extension GL_ARB_tessellation_shader : enable\n");
8436
8437 shader_generate_glsl_declarations(context_gl, buffer, shader, reg_maps, &priv_ctx);
8438
8439 shader_addline(buffer, "layout(");
8440 switch (shader->u.ds.tessellator_domain)
8441 {
8443 shader_addline(buffer, "isolines");
8444 break;
8446 shader_addline(buffer, "quads");
8447 break;
8449 shader_addline(buffer, "triangles");
8450 break;
8451 }
8452 switch (args->tessellator_output_primitive)
8453 {
8455 shader_addline(buffer, ", ccw");
8456 break;
8458 shader_addline(buffer, ", cw");
8459 break;
8461 shader_addline(buffer, ", point_mode");
8462 break;
8464 break;
8465 }
8466 switch (args->tessellator_partitioning)
8467 {
8469 shader_addline(buffer, ", fractional_odd_spacing");
8470 break;
8472 shader_addline(buffer, ", fractional_even_spacing");
8473 break;
8476 shader_addline(buffer, ", equal_spacing");
8477 break;
8478 }
8479 shader_addline(buffer, ") in;\n");
8480
8481 shader_addline(buffer, "in shader_in_out { vec4 reg[%u]; } shader_in[];\n", shader->limits->packed_input);
8482
8483 if (args->next_shader_type == WINED3D_SHADER_TYPE_PIXEL && !gl_info->supported[ARB_CLIP_CONTROL])
8484 shader_addline(buffer, "uniform vec4 pos_fixup;\n");
8485
8487 args->next_shader_type == WINED3D_SHADER_TYPE_PIXEL, args->interpolation_mode);
8488 shader_glsl_generate_patch_constant_setup(buffer, &shader->patch_constant_signature, TRUE);
8489
8490 shader_addline(buffer, "void main()\n{\n");
8491 shader_addline(buffer, "setup_patch_constant_input();\n");
8492
8493 if (FAILED(shader_generate_code(shader, buffer, reg_maps, &priv_ctx, NULL, NULL)))
8494 return 0;
8495
8496 shader_addline(buffer, "}\n");
8497
8498 shader_id = GL_EXTCALL(glCreateShader(GL_TESS_EVALUATION_SHADER));
8499 TRACE("Compiling shader object %u.\n", shader_id);
8500 shader_glsl_compile(gl_info, shader_id, buffer->buffer);
8501
8502 return shader_id;
8503}
static void shader_glsl_generate_sm4_output_setup(struct shader_glsl_priv *priv, const struct wined3d_shader *shader, unsigned int input_count, const struct wined3d_gl_info *gl_info, BOOL rasterizer_setup, const uint32_t *interpolation_mode)
Definition: glsl_shader.c:7535
static void shader_glsl_generate_patch_constant_setup(struct wined3d_string_buffer *buffer, const struct wined3d_shader_signature *signature, BOOL input_setup)
Definition: glsl_shader.c:7589
@ WINED3D_TESSELLATOR_OUTPUT_POINT
@ WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CW
@ WINED3D_TESSELLATOR_OUTPUT_TRIANGLE_CCW
@ WINED3D_TESSELLATOR_OUTPUT_LINE
@ WINED3D_TESSELLATOR_DOMAIN_TRIANGLE
@ WINED3D_TESSELLATOR_DOMAIN_QUAD
@ WINED3D_TESSELLATOR_DOMAIN_LINE
@ WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_ODD
@ WINED3D_TESSELLATOR_PARTITIONING_FRACTIONAL_EVEN
@ WINED3D_TESSELLATOR_PARTITIONING_INTEGER
@ WINED3D_TESSELLATOR_PARTITIONING_POW2

Referenced by find_glsl_domain_shader().

◆ shader_glsl_generate_ds_epilogue()

static void shader_glsl_generate_ds_epilogue ( const struct wined3d_gl_info *  gl_info,
struct wined3d_string_buffer *  buffer,
const struct wined3d_shader *  shader,
const struct ds_compile_args *  args 
)
static

Definition at line 8404 of file glsl_shader.c.

8407{
8408 shader_addline(buffer, "setup_ds_output(ds_out);\n");
8409
8410 if (args->next_shader_type == WINED3D_SHADER_TYPE_PIXEL && !gl_info->supported[ARB_CLIP_CONTROL])
8412}

Referenced by shader_glsl_generate_shader_epilogue().

◆ shader_glsl_generate_ffp_fragment_shader()

static GLuint shader_glsl_generate_ffp_fragment_shader ( struct shader_glsl_priv *  priv,
const struct ffp_frag_settings *  settings,
const struct wined3d_context_gl *  context_gl 
)
static

Definition at line 9688 of file glsl_shader.c.

9690{
9691 struct wined3d_string_buffer *tex_reg_name = string_buffer_get(&priv->string_buffers);
9692 enum wined3d_cmp_func alpha_test_func = settings->alpha_test_func + 1;
9694 BYTE lum_map = 0, bump_map = 0, tex_map = 0, tss_const_map = 0;
9695 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
9696 const BOOL legacy_syntax = needs_legacy_glsl_syntax(gl_info);
9697 BOOL tempreg_used = FALSE, tfactor_used = FALSE;
9698 GLuint shader_id;
9699 DWORD arg0, arg1, arg2;
9700 unsigned int stage;
9701
9703
9704 /* Find out which textures are read */
9705 for (stage = 0; stage < WINED3D_MAX_FFP_TEXTURES; ++stage)
9706 {
9707 if (settings->op[stage].cop == WINED3D_TOP_DISABLE)
9708 break;
9709
9710 arg0 = settings->op[stage].carg0 & WINED3DTA_SELECTMASK;
9711 arg1 = settings->op[stage].carg1 & WINED3DTA_SELECTMASK;
9712 arg2 = settings->op[stage].carg2 & WINED3DTA_SELECTMASK;
9713
9715 || (stage == 0 && settings->color_key_enabled))
9716 tex_map |= 1u << stage;
9718 tfactor_used = TRUE;
9719 if (arg0 == WINED3DTA_TEMP || arg1 == WINED3DTA_TEMP || arg2 == WINED3DTA_TEMP)
9720 tempreg_used = TRUE;
9721 if (settings->op[stage].tmp_dst)
9722 tempreg_used = TRUE;
9724 tss_const_map |= 1u << stage;
9725
9726 switch (settings->op[stage].cop)
9727 {
9729 lum_map |= 1u << stage;
9730 /* fall through */
9732 bump_map |= 1u << stage;
9733 /* fall through */
9736 tex_map |= 1u << stage;
9737 break;
9738
9740 tfactor_used = TRUE;
9741 break;
9742
9743 default:
9744 break;
9745 }
9746
9747 if (settings->op[stage].aop == WINED3D_TOP_DISABLE)
9748 continue;
9749
9750 arg0 = settings->op[stage].aarg0 & WINED3DTA_SELECTMASK;
9751 arg1 = settings->op[stage].aarg1 & WINED3DTA_SELECTMASK;
9752 arg2 = settings->op[stage].aarg2 & WINED3DTA_SELECTMASK;
9753
9755 tex_map |= 1u << stage;
9757 tfactor_used = TRUE;
9758 if (arg0 == WINED3DTA_TEMP || arg1 == WINED3DTA_TEMP || arg2 == WINED3DTA_TEMP)
9759 tempreg_used = TRUE;
9761 tss_const_map |= 1u << stage;
9762 }
9763
9765
9767 shader_addline(buffer, "#extension GL_ARB_explicit_attrib_location : enable\n");
9769 shader_addline(buffer, "#extension GL_ARB_shading_language_420pack : enable\n");
9770
9771 if (!use_legacy_fragment_output(gl_info))
9772 {
9773 shader_addline(buffer, "vec4 ps_out[1];\n");
9775 shader_addline(buffer, "layout(location = 0) ");
9776 shader_addline(buffer, "out vec4 color_out0;\n");
9777 }
9778
9779 shader_addline(buffer, "vec4 tmp0, tmp1;\n");
9780 shader_addline(buffer, "vec4 ret;\n");
9781 if (tempreg_used || settings->sRGB_write)
9782 shader_addline(buffer, "vec4 temp_reg = vec4(0.0);\n");
9783 shader_addline(buffer, "vec4 arg0, arg1, arg2;\n");
9784
9785 for (stage = 0; stage < WINED3D_MAX_FFP_TEXTURES; ++stage)
9786 {
9787 const char *sampler_type;
9788
9789 if (tss_const_map & (1u << stage))
9790 shader_addline(buffer, "uniform vec4 tss_const%u;\n", stage);
9791
9792 if (!(tex_map & (1u << stage)))
9793 continue;
9794
9795 switch (settings->op[stage].tex_type)
9796 {
9798 sampler_type = "1D";
9799 break;
9801 sampler_type = "2D";
9802 break;
9804 sampler_type = "3D";
9805 break;
9807 sampler_type = "Cube";
9808 break;
9809 default:
9810 FIXME("Unhandled sampler type %#x.\n", settings->op[stage].tex_type);
9811 sampler_type = NULL;
9812 break;
9813 }
9814 if (sampler_type)
9815 {
9818 shader_addline(buffer, "uniform sampler%s ps_sampler%u;\n", sampler_type, stage);
9819 }
9820
9821 shader_addline(buffer, "vec4 tex%u;\n", stage);
9822
9823 if (!(bump_map & (1u << stage)))
9824 continue;
9825 shader_addline(buffer, "uniform mat2 bumpenv_mat%u;\n", stage);
9826
9827 if (!(lum_map & (1u << stage)))
9828 continue;
9829 shader_addline(buffer, "uniform float bumpenv_lum_scale%u;\n", stage);
9830 shader_addline(buffer, "uniform float bumpenv_lum_offset%u;\n", stage);
9831 }
9832 if (tfactor_used)
9833 shader_addline(buffer, "uniform vec4 tex_factor;\n");
9834 if (settings->color_key_enabled)
9835 shader_addline(buffer, "uniform vec4 color_key[2];\n");
9836 shader_addline(buffer, "uniform vec4 specular_enable;\n");
9837
9838 if (settings->sRGB_write)
9839 {
9840 shader_addline(buffer, "const vec4 srgb_const0 = ");
9842 shader_addline(buffer, ";\n");
9843 shader_addline(buffer, "const vec4 srgb_const1 = ");
9845 shader_addline(buffer, ";\n");
9846 }
9847
9848 shader_addline(buffer, "uniform struct\n{\n");
9849 shader_addline(buffer, " vec4 color;\n");
9850 shader_addline(buffer, " float density;\n");
9851 shader_addline(buffer, " float end;\n");
9852 shader_addline(buffer, " float scale;\n");
9853 shader_addline(buffer, "} ffp_fog;\n");
9854
9855 if (alpha_test_func != WINED3D_CMP_ALWAYS)
9856 shader_addline(buffer, "uniform float alpha_test_ref;\n");
9857
9858 if (legacy_syntax)
9859 {
9860 shader_addline(buffer, "vec4 ffp_varying_diffuse;\n");
9861 shader_addline(buffer, "vec4 ffp_varying_specular;\n");
9862 shader_addline(buffer, "vec4 ffp_varying_texcoord[%u];\n", WINED3D_MAX_FFP_TEXTURES);
9863 shader_addline(buffer, "vec4 ffp_texcoord[%u];\n", WINED3D_MAX_FFP_TEXTURES);
9864 shader_addline(buffer, "float ffp_varying_fogcoord;\n");
9865 }
9866 else
9867 {
9868 declare_in_varying(gl_info, buffer, settings->flatshading, "vec4 ffp_varying_diffuse;\n");
9869 declare_in_varying(gl_info, buffer, settings->flatshading, "vec4 ffp_varying_specular;\n");
9870 declare_in_varying(gl_info, buffer, FALSE, "vec4 ffp_varying_texcoord[%u];\n", WINED3D_MAX_FFP_TEXTURES);
9871 shader_addline(buffer, "vec4 ffp_texcoord[%u];\n", WINED3D_MAX_FFP_TEXTURES);
9872 declare_in_varying(gl_info, buffer, FALSE, "float ffp_varying_fogcoord;\n");
9873 }
9874
9875 shader_addline(buffer, "void main()\n{\n");
9876
9877 if (legacy_syntax)
9878 {
9879 shader_addline(buffer, "ffp_varying_diffuse = gl_Color;\n");
9880 shader_addline(buffer, "ffp_varying_specular = gl_SecondaryColor;\n");
9881 }
9882
9883 for (stage = 0; stage < WINED3D_MAX_FFP_TEXTURES; ++stage)
9884 {
9885 if (tex_map & (1u << stage))
9886 {
9887 if (settings->pointsprite)
9888 shader_addline(buffer, "ffp_texcoord[%u] = vec4(gl_PointCoord.xy, 0.0, 0.0);\n", stage);
9889 else if (settings->texcoords_initialized & (1u << stage))
9890 shader_addline(buffer, "ffp_texcoord[%u] = %s[%u];\n",
9891 stage, legacy_syntax ? "gl_TexCoord" : "ffp_varying_texcoord", stage);
9892 else
9893 shader_addline(buffer, "ffp_texcoord[%u] = vec4(0.0);\n", stage);
9894 }
9895 }
9896
9897 if (legacy_syntax && settings->fog != WINED3D_FFP_PS_FOG_OFF)
9898 shader_addline(buffer, "ffp_varying_fogcoord = gl_FogFragCoord;\n");
9899
9900 /* Generate texture sampling instructions */
9901 for (stage = 0; stage < WINED3D_MAX_FFP_TEXTURES && settings->op[stage].cop != WINED3D_TOP_DISABLE; ++stage)
9902 {
9903 const char *texture_function, *coord_mask;
9904 BOOL proj;
9905
9906 if (!(tex_map & (1u << stage)))
9907 continue;
9908
9909 if (settings->op[stage].projected == WINED3D_PROJECTION_NONE)
9910 {
9911 proj = FALSE;
9912 }
9913 else if (settings->op[stage].projected == WINED3D_PROJECTION_COUNT4
9914 || settings->op[stage].projected == WINED3D_PROJECTION_COUNT3)
9915 {
9916 proj = TRUE;
9917 }
9918 else
9919 {
9920 FIXME("Unexpected projection mode %d\n", settings->op[stage].projected);
9921 proj = TRUE;
9922 }
9923
9924 if (settings->op[stage].tex_type == WINED3D_GL_RES_TYPE_TEX_CUBE)
9925 proj = FALSE;
9926
9927 switch (settings->op[stage].tex_type)
9928 {
9930 texture_function = "texture1D";
9931 coord_mask = "x";
9932 break;
9934 texture_function = "texture2D";
9935 coord_mask = "xy";
9936 break;
9938 texture_function = "texture3D";
9939 coord_mask = "xyz";
9940 break;
9942 texture_function = "textureCube";
9943 coord_mask = "xyz";
9944 break;
9945 default:
9946 FIXME("Unhandled texture type %#x.\n", settings->op[stage].tex_type);
9947 texture_function = "";
9948 coord_mask = "xyzw";
9949 proj = FALSE;
9950 break;
9951 }
9952 if (!legacy_syntax)
9953 texture_function = "texture";
9954
9955 if (stage > 0
9956 && (settings->op[stage - 1].cop == WINED3D_TOP_BUMPENVMAP
9957 || settings->op[stage - 1].cop == WINED3D_TOP_BUMPENVMAP_LUMINANCE))
9958 {
9959 shader_addline(buffer, "ret.xy = bumpenv_mat%u * tex%u.xy;\n", stage - 1, stage - 1);
9960
9961 /* With projective textures, texbem only divides the static
9962 * texture coordinate, not the displacement, so multiply the
9963 * displacement with the dividing parameter before passing it to
9964 * TXP. */
9965 if (settings->op[stage].projected != WINED3D_PROJECTION_NONE)
9966 {
9967 if (settings->op[stage].projected == WINED3D_PROJECTION_COUNT4)
9968 {
9969 shader_addline(buffer, "ret.xy = (ret.xy * ffp_texcoord[%u].w) + ffp_texcoord[%u].xy;\n",
9970 stage, stage);
9971 shader_addline(buffer, "ret.zw = ffp_texcoord[%u].ww;\n", stage);
9972 }
9973 else
9974 {
9975 shader_addline(buffer, "ret.xy = (ret.xy * ffp_texcoord[%u].z) + ffp_texcoord[%u].xy;\n",
9976 stage, stage);
9977 shader_addline(buffer, "ret.zw = ffp_texcoord[%u].zz;\n", stage);
9978 }
9979 }
9980 else
9981 {
9982 shader_addline(buffer, "ret = ffp_texcoord[%u] + ret.xyxy;\n", stage);
9983 }
9984
9985 shader_addline(buffer, "tex%u = %s%s(ps_sampler%u, ret.%s%s);\n",
9986 stage, texture_function, proj ? "Proj" : "", stage, coord_mask, proj ? "w" : "");
9987
9988 if (settings->op[stage - 1].cop == WINED3D_TOP_BUMPENVMAP_LUMINANCE)
9989 shader_addline(buffer, "tex%u *= clamp(tex%u.z * bumpenv_lum_scale%u + bumpenv_lum_offset%u, 0.0, 1.0);\n",
9990 stage, stage - 1, stage - 1, stage - 1);
9991 }
9992 else if (settings->op[stage].projected == WINED3D_PROJECTION_COUNT3)
9993 {
9994 shader_addline(buffer, "tex%u = %s%s(ps_sampler%u, ffp_texcoord[%u].xyz);\n",
9995 stage, texture_function, proj ? "Proj" : "", stage, stage);
9996 }
9997 else
9998 {
9999 shader_addline(buffer, "tex%u = %s%s(ps_sampler%u, ffp_texcoord[%u].%s%s);\n",
10000 stage, texture_function, proj ? "Proj" : "", stage, stage, coord_mask, proj ? "w" : "");
10001 }
10002
10003 string_buffer_sprintf(tex_reg_name, "tex%u", stage);
10005 settings->op[stage].color_fixup);
10006 }
10007
10008 if (settings->color_key_enabled)
10009 shader_glsl_generate_colour_key_test(buffer, "tex0", "color_key[0]", "color_key[1]");
10010
10011 shader_addline(buffer, "ret = ffp_varying_diffuse;\n");
10012
10013 /* Generate the main shader */
10014 for (stage = 0; stage < WINED3D_MAX_FFP_TEXTURES; ++stage)
10015 {
10016 BOOL op_equal;
10017
10018 if (settings->op[stage].cop == WINED3D_TOP_DISABLE)
10019 break;
10020
10021 if (settings->op[stage].cop == WINED3D_TOP_SELECT_ARG1
10022 && settings->op[stage].aop == WINED3D_TOP_SELECT_ARG1)
10023 op_equal = settings->op[stage].carg1 == settings->op[stage].aarg1;
10024 else if (settings->op[stage].cop == WINED3D_TOP_SELECT_ARG1
10025 && settings->op[stage].aop == WINED3D_TOP_SELECT_ARG2)
10026 op_equal = settings->op[stage].carg1 == settings->op[stage].aarg2;
10027 else if (settings->op[stage].cop == WINED3D_TOP_SELECT_ARG2
10028 && settings->op[stage].aop == WINED3D_TOP_SELECT_ARG1)
10029 op_equal = settings->op[stage].carg2 == settings->op[stage].aarg1;
10030 else if (settings->op[stage].cop == WINED3D_TOP_SELECT_ARG2
10031 && settings->op[stage].aop == WINED3D_TOP_SELECT_ARG2)
10032 op_equal = settings->op[stage].carg2 == settings->op[stage].aarg2;
10033 else
10034 op_equal = settings->op[stage].aop == settings->op[stage].cop
10035 && settings->op[stage].carg0 == settings->op[stage].aarg0
10036 && settings->op[stage].carg1 == settings->op[stage].aarg1
10037 && settings->op[stage].carg2 == settings->op[stage].aarg2;
10038
10039 if (settings->op[stage].aop == WINED3D_TOP_DISABLE)
10040 {
10041 shader_glsl_ffp_fragment_op(buffer, stage, TRUE, FALSE, settings->op[stage].tmp_dst,
10042 settings->op[stage].cop, settings->op[stage].carg0,
10043 settings->op[stage].carg1, settings->op[stage].carg2);
10044 }
10045 else if (op_equal)
10046 {
10047 shader_glsl_ffp_fragment_op(buffer, stage, TRUE, TRUE, settings->op[stage].tmp_dst,
10048 settings->op[stage].cop, settings->op[stage].carg0,
10049 settings->op[stage].carg1, settings->op[stage].carg2);
10050 }
10051 else if (settings->op[stage].cop != WINED3D_TOP_BUMPENVMAP
10052 && settings->op[stage].cop != WINED3D_TOP_BUMPENVMAP_LUMINANCE)
10053 {
10054 shader_glsl_ffp_fragment_op(buffer, stage, TRUE, FALSE, settings->op[stage].tmp_dst,
10055 settings->op[stage].cop, settings->op[stage].carg0,
10056 settings->op[stage].carg1, settings->op[stage].carg2);
10057 shader_glsl_ffp_fragment_op(buffer, stage, FALSE, TRUE, settings->op[stage].tmp_dst,
10058 settings->op[stage].aop, settings->op[stage].aarg0,
10059 settings->op[stage].aarg1, settings->op[stage].aarg2);
10060 }
10061 }
10062
10063 shader_addline(buffer, "%s[0] = ffp_varying_specular * specular_enable + ret;\n",
10064 get_fragment_output(gl_info));
10065
10066 if (settings->sRGB_write)
10068
10070
10071 shader_glsl_generate_alpha_test(buffer, gl_info, alpha_test_func);
10072 if (!use_legacy_fragment_output(gl_info))
10073 shader_addline(buffer, "color_out0 = ps_out[0];\n");
10074
10075 shader_addline(buffer, "}\n");
10076
10077 shader_id = GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER));
10078 shader_glsl_compile(gl_info, shader_id, buffer->buffer);
10079
10080 string_buffer_release(&priv->string_buffers, tex_reg_name);
10081 return shader_id;
10082}
const struct wined3d_vec4 wined3d_srgb_const[]
Definition: shader.c:32
static void shader_glsl_generate_alpha_test(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, enum wined3d_cmp_func alpha_func)
Definition: glsl_shader.c:7679
static void shader_glsl_generate_fog_code(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, enum wined3d_ffp_ps_fog_mode mode)
Definition: glsl_shader.c:7647
static void shader_glsl_generate_srgb_write_correction(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:7634
static void shader_glsl_ffp_fragment_op(struct wined3d_string_buffer *buffer, unsigned int stage, BOOL color, BOOL alpha, BOOL tmp_dst, unsigned int op, DWORD dw_arg0, DWORD dw_arg1, DWORD dw_arg2)
Definition: glsl_shader.c:9541
#define WINED3DTA_TEMP
Definition: wined3d.h:886
#define WINED3DTA_SELECTMASK
Definition: wined3d.h:880
wined3d_cmp_func
Definition: wined3d.h:460
#define WINED3DTA_CONSTANT
Definition: wined3d.h:887
@ WINED3D_GL_RES_TYPE_TEX_3D
@ WINED3D_GL_RES_TYPE_TEX_CUBE
@ WINED3D_GL_RES_TYPE_TEX_1D
@ WINED3D_FFP_PS_FOG_OFF
@ WINED3D_PROJECTION_COUNT3
@ WINED3D_PROJECTION_NONE
@ WINED3D_PROJECTION_COUNT4
unsigned char BYTE
Definition: xxhash.c:193

Referenced by shader_glsl_find_ffp_fragment_shader().

◆ shader_glsl_generate_ffp_vertex_shader()

static GLuint shader_glsl_generate_ffp_vertex_shader ( struct shader_glsl_priv *  priv,
const struct wined3d_ffp_vs_settings *  settings,
const struct wined3d_gl_info *  gl_info 
)
static

Definition at line 9148 of file glsl_shader.c.

9150{
9151 static const struct attrib_info
9152 {
9153 const char type[6];
9154 const char name[24];
9155 }
9156 attrib_info[] =
9157 {
9158 {"vec4", "ffp_attrib_position"}, /* WINED3D_FFP_POSITION */
9159 {"vec4", "ffp_attrib_blendweight"}, /* WINED3D_FFP_BLENDWEIGHT */
9160 /* TODO: Indexed vertex blending */
9161 {"float", ""}, /* WINED3D_FFP_BLENDINDICES */
9162 {"vec3", "ffp_attrib_normal"}, /* WINED3D_FFP_NORMAL */
9163 {"float", "ffp_attrib_psize"}, /* WINED3D_FFP_PSIZE */
9164 {"vec4", "ffp_attrib_diffuse"}, /* WINED3D_FFP_DIFFUSE */
9165 {"vec4", "ffp_attrib_specular"}, /* WINED3D_FFP_SPECULAR */
9166 };
9167 const BOOL legacy_syntax = needs_legacy_glsl_syntax(gl_info);
9169 BOOL output_legacy_fogcoord = legacy_syntax;
9170 BOOL legacy_lighting = priv->legacy_lighting;
9171 GLuint shader_obj;
9172 unsigned int i;
9173
9175
9177
9179 shader_addline(buffer, "#extension GL_ARB_explicit_attrib_location : enable\n");
9180
9181 shader_addline(buffer, "invariant gl_Position;\n");
9182
9183 for (i = 0; i < WINED3D_FFP_ATTRIBS_COUNT; ++i)
9184 {
9185 const char *type = i < ARRAY_SIZE(attrib_info) ? attrib_info[i].type : "vec4";
9186
9188 shader_addline(buffer, "layout(location = %u) ", i);
9189 shader_addline(buffer, "%s %s vs_in%u;\n", get_attribute_keyword(gl_info), type, i);
9190 }
9191 shader_addline(buffer, "\n");
9192
9193 shader_addline(buffer, "uniform mat4 ffp_modelview_matrix[%u];\n", MAX_VERTEX_BLENDS);
9194 shader_addline(buffer, "uniform mat4 ffp_projection_matrix;\n");
9195 shader_addline(buffer, "uniform mat4 ffp_normal_matrix;\n");
9196 shader_addline(buffer, "uniform mat4 ffp_texture_matrix[%u];\n", WINED3D_MAX_FFP_TEXTURES);
9197
9198 shader_addline(buffer, "uniform struct\n{\n");
9199 shader_addline(buffer, " vec4 emissive;\n");
9200 shader_addline(buffer, " vec4 ambient;\n");
9201 shader_addline(buffer, " vec4 diffuse;\n");
9202 shader_addline(buffer, " vec4 specular;\n");
9203 shader_addline(buffer, " float shininess;\n");
9204 shader_addline(buffer, "} ffp_material;\n");
9205
9206 shader_addline(buffer, "uniform vec3 ffp_light_ambient;\n");
9207 shader_addline(buffer, "uniform struct\n{\n");
9208 shader_addline(buffer, " vec4 diffuse;\n");
9209 shader_addline(buffer, " vec4 specular;\n");
9210 shader_addline(buffer, " vec4 ambient;\n");
9211 shader_addline(buffer, " vec4 position;\n");
9212 shader_addline(buffer, " vec3 direction;\n");
9213 shader_addline(buffer, " float range;\n");
9214 shader_addline(buffer, " float falloff;\n");
9215 shader_addline(buffer, " float c_att;\n");
9216 shader_addline(buffer, " float l_att;\n");
9217 shader_addline(buffer, " float q_att;\n");
9218 shader_addline(buffer, " float cos_htheta;\n");
9219 shader_addline(buffer, " float cos_hphi;\n");
9220 shader_addline(buffer, "} ffp_light[%u];\n", WINED3D_MAX_ACTIVE_LIGHTS);
9221
9222 if (settings->point_size)
9223 {
9224 shader_addline(buffer, "uniform struct\n{\n");
9225 shader_addline(buffer, " float size;\n");
9226 shader_addline(buffer, " float size_min;\n");
9227 shader_addline(buffer, " float size_max;\n");
9228 shader_addline(buffer, " float c_att;\n");
9229 shader_addline(buffer, " float l_att;\n");
9230 shader_addline(buffer, " float q_att;\n");
9231 shader_addline(buffer, "} ffp_point;\n");
9232 }
9233
9234 if (legacy_syntax)
9235 {
9236 shader_addline(buffer, "vec4 ffp_varying_diffuse;\n");
9237 shader_addline(buffer, "vec4 ffp_varying_specular;\n");
9238 shader_addline(buffer, "vec4 ffp_varying_texcoord[%u];\n", WINED3D_MAX_FFP_TEXTURES);
9239 shader_addline(buffer, "float ffp_varying_fogcoord;\n");
9240 }
9241 else
9242 {
9243 if (settings->clipping)
9244 shader_addline(buffer, "uniform vec4 clip_planes[%u];\n", gl_info->limits.user_clip_distances);
9245
9246 declare_out_varying(gl_info, buffer, settings->flatshading, "vec4 ffp_varying_diffuse;\n");
9247 declare_out_varying(gl_info, buffer, settings->flatshading, "vec4 ffp_varying_specular;\n");
9248 declare_out_varying(gl_info, buffer, FALSE, "vec4 ffp_varying_texcoord[%u];\n", WINED3D_MAX_FFP_TEXTURES);
9249 declare_out_varying(gl_info, buffer, FALSE, "float ffp_varying_fogcoord;\n");
9250 }
9251
9252 shader_addline(buffer, "\nvec3 ffp_normalize(vec3 n)\n{\n");
9253 shader_addline(buffer, " float lensq = dot(n, n);\n");
9254 shader_addline(buffer, " return lensq == 0.0 ? n : (n * inversesqrt(lensq));\n");
9255 shader_addline(buffer, "}\n");
9256
9257 shader_addline(buffer, "\nvoid main()\n{\n");
9258 shader_addline(buffer, "float m;\n");
9259 shader_addline(buffer, "vec3 r;\n");
9260
9261 for (i = 0; i < ARRAY_SIZE(attrib_info); ++i)
9262 {
9263 if (attrib_info[i].name[0])
9264 shader_addline(buffer, "%s %s = vs_in%u%s;\n", attrib_info[i].type, attrib_info[i].name,
9265 i, settings->swizzle_map & (1u << i) ? ".zyxw" : "");
9266 }
9267 for (i = 0; i < WINED3D_MAX_FFP_TEXTURES; ++i)
9268 {
9269 unsigned int coord_idx = settings->texgen[i] & 0x0000ffff;
9270 if ((settings->texgen[i] & 0xffff0000) == WINED3DTSS_TCI_PASSTHRU
9271 && settings->texcoords & (1u << i))
9272 shader_addline(buffer, "vec4 ffp_attrib_texcoord%u = vs_in%u;\n", i, coord_idx + WINED3D_FFP_TEXCOORD0);
9273 }
9274
9275 shader_addline(buffer, "ffp_attrib_blendweight[%u] = 1.0;\n", settings->vertexblends);
9276
9277 if (settings->transformed)
9278 {
9279 shader_addline(buffer, "vec4 ec_pos = vec4(ffp_attrib_position.xyz, 1.0);\n");
9280 shader_addline(buffer, "gl_Position = ffp_projection_matrix * ec_pos;\n");
9281 shader_addline(buffer, "if (ffp_attrib_position.w != 0.0) gl_Position /= ffp_attrib_position.w;\n");
9282 }
9283 else
9284 {
9285 for (i = 0; i < settings->vertexblends; ++i)
9286 shader_addline(buffer, "ffp_attrib_blendweight[%u] -= ffp_attrib_blendweight[%u];\n", settings->vertexblends, i);
9287
9288 shader_addline(buffer, "vec4 ec_pos = vec4(0.0);\n");
9289 for (i = 0; i < settings->vertexblends + 1; ++i)
9290 shader_addline(buffer, "ec_pos += ffp_attrib_blendweight[%u] * (ffp_modelview_matrix[%u] * vec4(ffp_attrib_position.xyz, 1.0));\n", i, i);
9291
9292 shader_addline(buffer, "gl_Position = ffp_projection_matrix * ec_pos;\n");
9293 if (settings->clipping)
9294 {
9295 if (legacy_syntax)
9296 shader_addline(buffer, "gl_ClipVertex = ec_pos;\n");
9297 else
9298 for (i = 0; i < gl_info->limits.user_clip_distances; ++i)
9299 shader_addline(buffer, "gl_ClipDistance[%u] = dot(ec_pos, clip_planes[%u]);\n", i, i);
9300 }
9301 shader_addline(buffer, "ec_pos /= ec_pos.w;\n");
9302 }
9303
9304 shader_addline(buffer, "vec3 normal = vec3(0.0);\n");
9305 if (settings->normal)
9306 {
9307 if (!settings->vertexblends)
9308 {
9309 if (settings->transformed)
9310 shader_addline(buffer, "normal = ffp_attrib_normal;\n");
9311 else
9312 shader_addline(buffer, "normal = mat3(ffp_normal_matrix) * ffp_attrib_normal;\n");
9313 }
9314 else
9315 {
9316 for (i = 0; i < settings->vertexblends + 1; ++i)
9317 {
9318 if (settings->transformed)
9319 shader_addline(buffer, "normal += ffp_attrib_blendweight[%u] * ffp_attrib_normal;\n", i);
9320 else
9321 shader_addline(buffer, "normal += ffp_attrib_blendweight[%u] * (mat3(ffp_modelview_matrix[%u]) * ffp_attrib_normal);\n", i, i);
9322 }
9323 }
9324
9325 if (settings->normalize)
9326 shader_addline(buffer, "normal = ffp_normalize(normal);\n");
9327 }
9328
9330 if (legacy_syntax)
9331 {
9332 shader_addline(buffer, "gl_FrontColor = ffp_varying_diffuse;\n");
9333 shader_addline(buffer, "gl_FrontSecondaryColor = ffp_varying_specular;\n");
9334 }
9335 else
9336 {
9337 shader_addline(buffer, "ffp_varying_diffuse = clamp(ffp_varying_diffuse, 0.0, 1.0);\n");
9338 shader_addline(buffer, "ffp_varying_specular = clamp(ffp_varying_specular, 0.0, 1.0);\n");
9339 }
9340
9341 for (i = 0; i < WINED3D_MAX_FFP_TEXTURES; ++i)
9342 {
9343 struct wined3d_string_buffer *texcoord = string_buffer_get(&priv->string_buffers);
9344 bool output_texcoord = true;
9345
9346 if (!settings->transformed)
9347 shader_addline(texcoord, "ffp_texture_matrix[%u] * ", i);
9348
9349 switch (settings->texgen[i] & 0xffff0000)
9350 {
9352 if (settings->texcoords & (1u << i))
9353 shader_addline(texcoord, "ffp_attrib_texcoord%u", i);
9354 else if (shader_glsl_full_ffp_varyings(gl_info))
9355 shader_addline(texcoord, "vec4(0.0)");
9356 else
9357 output_texcoord = false;
9358 break;
9359
9361 shader_addline(texcoord, "vec4(normal, 1.0)");
9362 break;
9363
9365 shader_addline(texcoord, "ec_pos");
9366 break;
9367
9369 shader_addline(texcoord, "vec4(reflect(ffp_normalize(ec_pos.xyz), normal), 1.0)");
9370 break;
9371
9373 shader_addline(buffer, "r = reflect(ffp_normalize(ec_pos.xyz), normal);\n");
9374 shader_addline(buffer, "m = 2.0 * length(vec3(r.x, r.y, r.z + 1.0));\n");
9375 shader_addline(texcoord, "vec4(r.x / m + 0.5, r.y / m + 0.5, 0.0, 1.0)");
9376 break;
9377
9378 default:
9379 ERR("Unhandled texgen %#x.\n", settings->texgen[i]);
9380 break;
9381 }
9382 if (output_texcoord)
9383 {
9384 shader_addline(buffer, "ffp_varying_texcoord[%u] = %s;\n", i, texcoord->buffer);
9385 if (legacy_syntax)
9386 shader_addline(buffer, "gl_TexCoord[%u] = ffp_varying_texcoord[%u];\n", i, i);
9387 }
9388 string_buffer_release(&priv->string_buffers, texcoord);
9389 }
9390
9391 switch (settings->fog_mode)
9392 {
9394 output_legacy_fogcoord = FALSE;
9395 break;
9396
9398 shader_addline(buffer, "ffp_varying_fogcoord = ffp_attrib_specular.w;\n");
9399 break;
9400
9402 shader_addline(buffer, "ffp_varying_fogcoord = length(ec_pos.xyz);\n");
9403 break;
9404
9406 if (settings->ortho_fog)
9407 {
9408 if (gl_info->supported[ARB_CLIP_CONTROL])
9409 shader_addline(buffer, "ffp_varying_fogcoord = gl_Position.z;\n");
9410 else
9411 /* Need to undo the [0.0 - 1.0] -> [-1.0 - 1.0] transformation from D3D to GL coordinates. */
9412 shader_addline(buffer, "ffp_varying_fogcoord = gl_Position.z * 0.5 + 0.5;\n");
9413 }
9414 else if (settings->transformed)
9415 {
9416 shader_addline(buffer, "ffp_varying_fogcoord = ec_pos.z;\n");
9417 }
9418 else
9419 {
9420 shader_addline(buffer, "ffp_varying_fogcoord = abs(ec_pos.z);\n");
9421 }
9422 break;
9423
9424 default:
9425 ERR("Unhandled fog mode %#x.\n", settings->fog_mode);
9426 break;
9427 }
9428 if (output_legacy_fogcoord)
9429 shader_addline(buffer, "gl_FogFragCoord = ffp_varying_fogcoord;\n");
9430
9431 if (settings->point_size)
9432 {
9433 shader_addline(buffer, "gl_PointSize = %s / sqrt(ffp_point.c_att"
9434 " + ffp_point.l_att * length(ec_pos.xyz)"
9435 " + ffp_point.q_att * dot(ec_pos.xyz, ec_pos.xyz));\n",
9436 settings->per_vertex_point_size ? "ffp_attrib_psize" : "ffp_point.size");
9437 shader_addline(buffer, "gl_PointSize = clamp(gl_PointSize, ffp_point.size_min, ffp_point.size_max);\n");
9438 }
9439
9440 shader_addline(buffer, "}\n");
9441
9442 shader_obj = GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER));
9443 shader_glsl_compile(gl_info, shader_obj, buffer->buffer);
9444
9445 return shader_obj;
9446}
static void shader_glsl_ffp_vertex_lighting(struct wined3d_string_buffer *buffer, const struct wined3d_ffp_vs_settings *settings, BOOL legacy_lighting)
Definition: glsl_shader.c:9016
#define WINED3DTSS_TCI_PASSTHRU
Definition: wined3d.h:874
#define WINED3DTSS_TCI_CAMERASPACENORMAL
Definition: wined3d.h:875
#define WINED3DTSS_TCI_SPHEREMAP
Definition: wined3d.h:878
#define WINED3DTSS_TCI_CAMERASPACEPOSITION
Definition: wined3d.h:876
#define WINED3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR
Definition: wined3d.h:877
@ WINED3D_FFP_TEXCOORD0
@ WINED3D_FFP_VS_FOG_FOGCOORD
@ WINED3D_FFP_VS_FOG_OFF
@ WINED3D_FFP_VS_FOG_DEPTH
@ WINED3D_FFP_VS_FOG_RANGE

Referenced by shader_glsl_find_ffp_vertex_shader().

◆ shader_glsl_generate_fog_code()

static void shader_glsl_generate_fog_code ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info,
enum wined3d_ffp_ps_fog_mode  mode 
)
static

Definition at line 7647 of file glsl_shader.c.

7649{
7650 const char *output = get_fragment_output(gl_info);
7651
7652 switch (mode)
7653 {
7655 return;
7656
7658 shader_addline(buffer, "float fog = (ffp_fog.end - ffp_varying_fogcoord) * ffp_fog.scale;\n");
7659 break;
7660
7662 shader_addline(buffer, "float fog = exp(-ffp_fog.density * ffp_varying_fogcoord);\n");
7663 break;
7664
7666 shader_addline(buffer, "float fog = exp(-ffp_fog.density * ffp_fog.density"
7667 " * ffp_varying_fogcoord * ffp_varying_fogcoord);\n");
7668 break;
7669
7670 default:
7671 ERR("Invalid fog mode %#x.\n", mode);
7672 return;
7673 }
7674
7675 shader_addline(buffer, "%s[0].xyz = mix(ffp_fog.color.xyz, %s[0].xyz, clamp(fog, 0.0, 1.0));\n",
7676 output, output);
7677}
@ WINED3D_FFP_PS_FOG_EXP
@ WINED3D_FFP_PS_FOG_EXP2
@ WINED3D_FFP_PS_FOG_LINEAR

Referenced by shader_glsl_generate_ffp_fragment_shader(), and shader_glsl_generate_ps_epilogue().

◆ shader_glsl_generate_fragment_shader()

static GLuint shader_glsl_generate_fragment_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
const struct wined3d_shader *  shader,
const struct ps_compile_args *  args 
)
static

Definition at line 7837 of file glsl_shader.c.

7839{
7840 const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
7841 struct wined3d_string_buffer_list *string_buffers = &priv->string_buffers;
7842 const struct wined3d_shader_version *version = &reg_maps->shader_version;
7843 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
7845 const char *prefix = shader_glsl_get_prefix(version->type);
7846 BOOL legacy_syntax = needs_legacy_glsl_syntax(gl_info);
7847 unsigned int i, extra_constants_needed = 0;
7848 struct shader_glsl_ctx_priv priv_ctx;
7849 GLuint shader_id;
7850 uint32_t map;
7851
7852 if (priv->use_vkd3d)
7854
7855 memset(&priv_ctx, 0, sizeof(priv_ctx));
7856 priv_ctx.gl_info = gl_info;
7857 priv_ctx.cur_ps_args = args;
7858 priv_ctx.string_buffers = string_buffers;
7859
7861
7863 if (gl_info->supported[ARB_CONSERVATIVE_DEPTH])
7864 shader_addline(buffer, "#extension GL_ARB_conservative_depth : enable\n");
7865 if (gl_info->supported[ARB_DERIVATIVE_CONTROL])
7866 shader_addline(buffer, "#extension GL_ARB_derivative_control : enable\n");
7868 shader_addline(buffer, "#extension GL_ARB_explicit_attrib_location : enable\n");
7870 shader_addline(buffer, "#extension GL_ARB_fragment_coord_conventions : enable\n");
7871 if (gl_info->supported[ARB_FRAGMENT_LAYER_VIEWPORT])
7872 shader_addline(buffer, "#extension GL_ARB_fragment_layer_viewport : enable\n");
7873 if (gl_info->supported[ARB_SAMPLE_SHADING])
7874 shader_addline(buffer, "#extension GL_ARB_sample_shading : enable\n");
7875 if (gl_info->supported[ARB_SHADER_TEXTURE_LOD])
7876 shader_addline(buffer, "#extension GL_ARB_shader_texture_lod : enable\n");
7877
7878 /* Base Declarations */
7879 shader_generate_glsl_declarations(context_gl, buffer, shader, reg_maps, &priv_ctx);
7880
7881 if (gl_info->supported[ARB_CONSERVATIVE_DEPTH])
7882 {
7883 if (shader->u.ps.depth_output == WINED3DSPR_DEPTHOUTGE)
7884 shader_addline(buffer, "layout (depth_greater) out float gl_FragDepth;\n");
7885 else if (shader->u.ps.depth_output == WINED3DSPR_DEPTHOUTLE)
7886 shader_addline(buffer, "layout (depth_less) out float gl_FragDepth;\n");
7887 }
7888
7889 if (version->major < 3 || args->vp_mode != WINED3D_VP_MODE_SHADER)
7890 {
7891 shader_addline(buffer, "uniform struct\n{\n");
7892 shader_addline(buffer, " vec4 color;\n");
7893 shader_addline(buffer, " float density;\n");
7894 shader_addline(buffer, " float end;\n");
7895 shader_addline(buffer, " float scale;\n");
7896 shader_addline(buffer, "} ffp_fog;\n");
7897
7898 if (legacy_syntax)
7899 {
7901 shader_addline(buffer, "vec4 ffp_varying_diffuse;\n");
7903 shader_addline(buffer, "vec4 ffp_varying_specular;\n");
7904 shader_addline(buffer, "vec4 ffp_texcoord[%u];\n", WINED3D_MAX_FFP_TEXTURES);
7905 shader_addline(buffer, "float ffp_varying_fogcoord;\n");
7906 }
7907 else
7908 {
7910 declare_in_varying(gl_info, buffer, args->flatshading, "vec4 ffp_varying_diffuse;\n");
7912 declare_in_varying(gl_info, buffer, args->flatshading, "vec4 ffp_varying_specular;\n");
7913 declare_in_varying(gl_info, buffer, FALSE, "vec4 ffp_varying_texcoord[%u];\n", WINED3D_MAX_FFP_TEXTURES);
7914 shader_addline(buffer, "vec4 ffp_texcoord[%u];\n", WINED3D_MAX_FFP_TEXTURES);
7915 declare_in_varying(gl_info, buffer, FALSE, "float ffp_varying_fogcoord;\n");
7916 }
7917 }
7918
7919 if (version->major >= 3)
7920 {
7921 unsigned int in_count = min(vec4_varyings(version->major, gl_info), shader->limits->packed_input);
7922
7923 if (args->vp_mode == WINED3D_VP_MODE_SHADER && reg_maps->input_registers)
7925 shader->u.ps.interpolation_mode, version->major >= 4);
7926 shader_addline(buffer, "vec4 %s_in[%u];\n", prefix, in_count);
7927 }
7928
7929 map = reg_maps->bumpmat;
7930 while (map)
7931 {
7933 shader_addline(buffer, "uniform mat2 bumpenv_mat%u;\n", i);
7934
7935 if (reg_maps->luminanceparams & (1u << i))
7936 {
7937 shader_addline(buffer, "uniform float bumpenv_lum_scale%u;\n", i);
7938 shader_addline(buffer, "uniform float bumpenv_lum_offset%u;\n", i);
7939 extra_constants_needed++;
7940 }
7941
7942 extra_constants_needed++;
7943 }
7944
7945 if (args->srgb_correction)
7946 {
7947 shader_addline(buffer, "const vec4 srgb_const0 = ");
7949 shader_addline(buffer, ";\n");
7950 shader_addline(buffer, "const vec4 srgb_const1 = ");
7952 shader_addline(buffer, ";\n");
7953 }
7954 if (reg_maps->vpos)
7955 {
7957 {
7958 if (context_gl->c.d3d_info->wined3d_creation_flags & WINED3D_PIXEL_CENTER_INTEGER)
7959 shader_addline(buffer, "layout(pixel_center_integer) in vec4 gl_FragCoord;\n");
7960 }
7961 shader_addline(buffer, "vec4 vpos;\n");
7962 }
7963
7964 if (args->alpha_test_func + 1 != WINED3D_CMP_ALWAYS)
7965 shader_addline(buffer, "uniform float alpha_test_ref;\n");
7966
7968 {
7969 const struct wined3d_shader_signature *output_signature = &shader->output_signature;
7970
7971 if (args->dual_source_blend)
7972 shader_addline(buffer, "vec4 ps_out[2];\n");
7973 else
7974 shader_addline(buffer, "vec4 ps_out[%u];\n", gl_info->limits.buffers);
7975 if (output_signature->element_count)
7976 {
7977 for (i = 0; i < output_signature->element_count; ++i)
7978 {
7979 const struct wined3d_shader_signature_element *output = &output_signature->elements[i];
7980
7981 if (output->register_idx == ~0u)
7982 continue;
7983 if ((unsigned int)output->component_type >= ARRAY_SIZE(component_type_info))
7984 {
7985 FIXME("Unhandled component type %#x.\n", output->component_type);
7986 continue;
7987 }
7989 {
7990 if (args->dual_source_blend)
7991 shader_addline(buffer, "layout(location = 0, index = %u) ", output->semantic_idx);
7992 else
7993 shader_addline(buffer, "layout(location = %u) ", output->semantic_idx);
7994 }
7995 shader_addline(buffer, "out %s4 color_out%u;\n",
7996 component_type_info[output->component_type].glsl_vector_type, output->semantic_idx);
7997 }
7998 }
7999 else
8000 {
8001 uint32_t mask = reg_maps->rt_mask;
8002
8003 while (mask)
8004 {
8007 {
8008 if (args->dual_source_blend)
8009 shader_addline(buffer, "layout(location = 0, index = %u) ", i);
8010 else
8011 shader_addline(buffer, "layout(location = %u) ", i);
8012 }
8013 shader_addline(buffer, "out vec4 color_out%u;\n", i);
8014 }
8015 }
8016 }
8017
8018 if (shader->limits->constant_float + extra_constants_needed >= gl_info->limits.glsl_ps_float_constants)
8019 FIXME("Insufficient uniforms to run this shader.\n");
8020
8021 if (shader->u.ps.force_early_depth_stencil)
8022 shader_addline(buffer, "layout(early_fragment_tests) in;\n");
8023
8024 shader_addline(buffer, "void main()\n{\n");
8025
8026 if (reg_maps->sample_mask)
8027 shader_addline(buffer, "float sample_mask = uintBitsToFloat(0xffffffffu);\n");
8028
8029 if (reg_maps->stencil_ref)
8030 shader_addline(buffer, "float stencil_ref = uintBitsToFloat(0xffffffffu);\n");
8031
8032 /* Direct3D applications expect integer vPos values, while OpenGL drivers
8033 * add approximately 0.5. This causes off-by-one problems as spotted by
8034 * the vPos d3d9 visual test. Unfortunately ATI cards do not add exactly
8035 * 0.5, but rather something like 0.49999999 or 0.50000001, which still
8036 * causes precision troubles when we just subtract 0.5.
8037 *
8038 * To deal with that, just floor() the position. This will eliminate the
8039 * fraction on all cards.
8040 *
8041 * TODO: Test how this behaves with multisampling.
8042 *
8043 * An advantage of floor is that it works even if the driver doesn't add
8044 * 0.5. It is somewhat questionable if 1.5, 2.5, ... are the proper values
8045 * to return in gl_FragCoord, even though coordinates specify the pixel
8046 * centers instead of the pixel corners. This code will behave correctly
8047 * on drivers that returns integer values. */
8048 if (reg_maps->vpos)
8049 {
8051 && (context_gl->c.d3d_info->wined3d_creation_flags & WINED3D_PIXEL_CENTER_INTEGER))
8052 shader_addline(buffer, "vpos = floor(gl_FragCoord);\n");
8053 else
8054 shader_addline(buffer, "vpos = gl_FragCoord;\n");
8055 }
8056
8057 if (reg_maps->shader_version.major < 3 || args->vp_mode != WINED3D_VP_MODE_SHADER)
8058 {
8059 unsigned int i;
8060
8061 if (legacy_syntax)
8062 {
8064 shader_addline(buffer, "ffp_varying_diffuse = gl_Color;\n");
8066 shader_addline(buffer, "ffp_varying_specular = gl_SecondaryColor;\n");
8067 }
8068
8069 map = reg_maps->texcoord;
8070 while (map)
8071 {
8073 if (args->pointsprite)
8074 shader_addline(buffer, "ffp_texcoord[%u] = vec4(gl_PointCoord.xy, 0.0, 0.0);\n", i);
8075 else if (args->texcoords_initialized & (1u << i))
8076 shader_addline(buffer, "ffp_texcoord[%u] = %s[%u];\n", i,
8077 legacy_syntax ? "gl_TexCoord" : "ffp_varying_texcoord", i);
8078 else
8079 shader_addline(buffer, "ffp_texcoord[%u] = vec4(0.0);\n", i);
8080 shader_addline(buffer, "vec4 T%u = ffp_texcoord[%u];\n", i, i);
8081 }
8082
8083 if (legacy_syntax)
8084 shader_addline(buffer, "ffp_varying_fogcoord = gl_FogFragCoord;\n");
8085 }
8086
8087 /* Pack 3.0 inputs */
8088 if (reg_maps->shader_version.major >= 3)
8089 shader_glsl_input_pack(shader, buffer, &shader->input_signature, reg_maps, args, gl_info,
8090 reg_maps->shader_version.major >= 4);
8091
8092 /* Base Shader Body */
8093 if (FAILED(shader_generate_code(shader, buffer, reg_maps, &priv_ctx, NULL, NULL)))
8094 return 0;
8095
8096 /* In SM4+ the shader epilogue is generated by the "ret" instruction. */
8097 if (reg_maps->shader_version.major < 4)
8098 shader_glsl_generate_ps_epilogue(gl_info, buffer, shader, args, string_buffers);
8099
8100 shader_addline(buffer, "}\n");
8101
8102 shader_id = GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER));
8103 TRACE("Compiling shader object %u.\n", shader_id);
8104 shader_glsl_compile(gl_info, shader_id, buffer->buffer);
8105
8106 return shader_id;
8107}
static BOOL glsl_is_color_reg_read(const struct wined3d_shader *shader, unsigned int idx)
Definition: glsl_shader.c:2298
static void shader_glsl_declare_shader_inputs(const struct wined3d_gl_info *gl_info, struct wined3d_string_buffer *buffer, unsigned int element_count, const uint32_t *interpolation_mode, BOOL unroll)
Definition: glsl_shader.c:2181
static void shader_glsl_input_pack(const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer, const struct wined3d_shader_signature *input_signature, const struct wined3d_shader_reg_maps *reg_maps, const struct ps_compile_args *args, const struct wined3d_gl_info *gl_info, BOOL unroll)
Definition: glsl_shader.c:6936
static void shader_glsl_generate_ps_epilogue(const struct wined3d_gl_info *gl_info, struct wined3d_string_buffer *buffer, const struct wined3d_shader *shader, const struct ps_compile_args *args, struct wined3d_string_buffer_list *string_buffers)
Definition: glsl_shader.c:7807
@ ARB_DERIVATIVE_CONTROL
Definition: wined3d_gl.h:69
@ ARB_FRAGMENT_LAYER_VIEWPORT
Definition: wined3d_gl.h:79
@ ARB_CONSERVATIVE_DEPTH
Definition: wined3d_gl.h:61
@ ARB_FRAGMENT_COORD_CONVENTIONS
Definition: wined3d_gl.h:78
@ ARB_SHADER_TEXTURE_LOD
Definition: wined3d_gl.h:116
@ ARB_SAMPLE_SHADING
Definition: wined3d_gl.h:105
@ WINED3D_VP_MODE_SHADER
@ WINED3DSPR_DEPTHOUTGE
@ WINED3DSPR_DEPTHOUTLE

Referenced by find_glsl_fragment_shader().

◆ shader_glsl_generate_geometry_shader()

static GLuint shader_glsl_generate_geometry_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
const struct wined3d_shader *  shader,
const struct gs_compile_args *  args 
)
static

Definition at line 8506 of file glsl_shader.c.

8508{
8509 struct wined3d_string_buffer_list *string_buffers = &priv->string_buffers;
8510 const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
8511 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
8513 const struct wined3d_shader_signature_element *output;
8514 enum wined3d_primitive_type primitive_type;
8515 struct shader_glsl_ctx_priv priv_ctx;
8516 unsigned int max_vertices;
8517 unsigned int i, j;
8518 GLuint shader_id;
8519
8520 if (shader->function && priv->use_vkd3d)
8522
8523 memset(&priv_ctx, 0, sizeof(priv_ctx));
8524 priv_ctx.gl_info = gl_info;
8525 priv_ctx.string_buffers = string_buffers;
8526
8528
8530
8531 shader_generate_glsl_declarations(context_gl, buffer, shader, reg_maps, &priv_ctx);
8532
8533 primitive_type = shader->u.gs.input_type ? shader->u.gs.input_type : args->primitive_type;
8534 shader_addline(buffer, "layout(%s", glsl_primitive_type_from_d3d(primitive_type));
8535 if (shader->u.gs.instance_count > 1)
8536 shader_addline(buffer, ", invocations = %u", shader->u.gs.instance_count);
8537 shader_addline(buffer, ") in;\n");
8538
8539 primitive_type = shader->u.gs.output_type ? shader->u.gs.output_type : args->primitive_type;
8540 if (!(max_vertices = shader->u.gs.vertices_out))
8541 {
8542 switch (args->primitive_type)
8543 {
8545 max_vertices = 1;
8546 break;
8548 max_vertices = 2;
8549 break;
8551 max_vertices = 3;
8552 break;
8553 default:
8554 FIXME("Unhandled primitive type %s.\n", debug_d3dprimitivetype(args->primitive_type));
8555 break;
8556 }
8557 }
8558 shader_addline(buffer, "layout(%s, max_vertices = %u) out;\n",
8559 glsl_primitive_type_from_d3d(primitive_type), max_vertices);
8560 shader_addline(buffer, "in shader_in_out { vec4 reg[%u]; } shader_in[];\n", shader->limits->packed_input);
8561
8562 if (!gl_info->supported[ARB_CLIP_CONTROL])
8563 {
8564 shader_addline(buffer, "uniform vec4 pos_fixup");
8565 if (reg_maps->viewport_array)
8567 shader_addline(buffer, ";\n");
8568 }
8569
8571 {
8573 }
8574 else
8575 {
8577 gl_info, TRUE, args->interpolation_mode);
8578 }
8579
8580 shader_addline(buffer, "void main()\n{\n");
8581 if (shader->function)
8582 {
8583 if (FAILED(shader_generate_code(shader, buffer, reg_maps, &priv_ctx, NULL, NULL)))
8584 return 0;
8585 }
8586 else
8587 {
8588 for (i = 0; i < max_vertices; ++i)
8589 {
8590 for (j = 0; j < shader->output_signature.element_count; ++j)
8591 {
8592 output = &shader->output_signature.elements[j];
8593 shader_addline(buffer, "gs_out[%u] = shader_in[%u].reg[%u];\n",
8594 output->register_idx, i, output->register_idx);
8595 }
8596 shader_addline(buffer, "setup_gs_output(gs_out);\n");
8597 if (!gl_info->supported[ARB_CLIP_CONTROL])
8599 shader_addline(buffer, "EmitVertex();\n");
8600 }
8601 }
8602 shader_addline(buffer, "}\n");
8603
8604 shader_id = GL_EXTCALL(glCreateShader(GL_GEOMETRY_SHADER));
8605 TRACE("Compiling shader object %u.\n", shader_id);
8606 shader_glsl_compile(gl_info, shader_id, buffer->buffer);
8607
8608 return shader_id;
8609}
static const char * glsl_primitive_type_from_d3d(enum wined3d_primitive_type primitive_type)
Definition: glsl_shader.c:2267
static void shader_glsl_generate_stream_output_setup(struct wined3d_string_buffer *buffer, const struct wined3d_shader *shader)
Definition: glsl_shader.c:7462
wined3d_primitive_type
Definition: wined3d.h:74
#define WINED3D_MAX_VIEWPORTS
Definition: wined3d.h:1590

Referenced by find_glsl_geometry_shader().

◆ shader_glsl_generate_hull_shader()

static GLuint shader_glsl_generate_hull_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
const struct wined3d_shader *  shader 
)
static

Definition at line 8314 of file glsl_shader.c.

8316{
8317 struct wined3d_string_buffer_list *string_buffers = &priv->string_buffers;
8318 const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
8319 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
8321 const struct wined3d_hull_shader *hs = &shader->u.hs;
8322 const struct wined3d_shader_phase *phase;
8323 struct shader_glsl_ctx_priv priv_ctx;
8324 GLuint shader_id;
8325 unsigned int i;
8326
8327 if (priv->use_vkd3d)
8329
8330 memset(&priv_ctx, 0, sizeof(priv_ctx));
8331 priv_ctx.gl_info = gl_info;
8332 priv_ctx.string_buffers = string_buffers;
8333
8335
8337 shader_addline(buffer, "#extension GL_ARB_tessellation_shader : enable\n");
8338
8339 shader_generate_glsl_declarations(context_gl, buffer, shader, reg_maps, &priv_ctx);
8340
8341 shader_addline(buffer, "layout(vertices = %u) out;\n", hs->output_vertex_count);
8342
8343 shader_addline(buffer, "in shader_in_out { vec4 reg[%u]; } shader_in[];\n", shader->limits->packed_input);
8344 shader_addline(buffer, "out shader_in_out { vec4 reg[%u]; } shader_out[];\n", shader->limits->packed_output);
8345
8346 shader_glsl_generate_patch_constant_setup(buffer, &shader->patch_constant_signature, FALSE);
8347
8348 if (hs->phases.control_point)
8349 {
8350 shader_addline(buffer, "void setup_hs_output(in vec4 outputs[%u])\n{\n",
8351 shader->limits->packed_output);
8352 shader_glsl_setup_sm4_shader_output(priv, shader->limits->packed_output, &shader->output_signature,
8353 &shader->reg_maps, "shader_out[gl_InvocationID]", FALSE);
8354 shader_addline(buffer, "}\n");
8355 }
8356
8357 shader_addline(buffer, "void hs_control_point_phase()\n{\n");
8358 if ((phase = hs->phases.control_point))
8359 {
8360 for (i = 0; i < phase->temporary_count; ++i)
8361 shader_addline(buffer, "vec4 R%u;\n", i);
8362 if (FAILED(shader_generate_code(shader, buffer, reg_maps, &priv_ctx, phase->start, phase->end)))
8363 return 0;
8364 shader_addline(buffer, "setup_hs_output(hs_out);\n");
8365 }
8366 else
8367 {
8369 }
8370 shader_addline(buffer, "}\n");
8371
8372 for (i = 0; i < hs->phases.fork_count; ++i)
8373 {
8374 if (FAILED(shader_glsl_generate_shader_phase(shader, buffer, reg_maps, &priv_ctx,
8375 &hs->phases.fork[i], "fork", i)))
8376 return 0;
8377 }
8378
8379 for (i = 0; i < hs->phases.join_count; ++i)
8380 {
8381 if (FAILED(shader_glsl_generate_shader_phase(shader, buffer, reg_maps, &priv_ctx,
8382 &hs->phases.join[i], "join", i)))
8383 return 0;
8384 }
8385
8386 shader_addline(buffer, "void main()\n{\n");
8387 shader_addline(buffer, "hs_control_point_phase();\n");
8388 if (reg_maps->vocp)
8389 shader_addline(buffer, "barrier();\n");
8390 for (i = 0; i < hs->phases.fork_count; ++i)
8392 for (i = 0; i < hs->phases.join_count; ++i)
8394 shader_addline(buffer, "setup_patch_constant_output();\n");
8395 shader_addline(buffer, "}\n");
8396
8397 shader_id = GL_EXTCALL(glCreateShader(GL_TESS_CONTROL_SHADER));
8398 TRACE("Compiling shader object %u.\n", shader_id);
8399 shader_glsl_compile(gl_info, shader_id, buffer->buffer);
8400
8401 return shader_id;
8402}
static void shader_glsl_generate_shader_phase_invocation(struct wined3d_string_buffer *buffer, const struct wined3d_shader_phase *phase, const char *phase_name, unsigned int phase_idx)
Definition: glsl_shader.c:8299
static HRESULT shader_glsl_generate_shader_phase(const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer, const struct wined3d_shader_reg_maps *reg_maps, struct shader_glsl_ctx_priv *priv_ctx, const struct wined3d_shader_phase *phase, const char *phase_name, unsigned phase_idx)
Definition: glsl_shader.c:8282
static void shader_glsl_generate_default_control_point_phase(const struct wined3d_shader *shader, struct wined3d_string_buffer *buffer, const struct wined3d_shader_reg_maps *reg_maps)
Definition: glsl_shader.c:8265
static void shader_glsl_setup_sm4_shader_output(struct shader_glsl_priv *priv, unsigned int input_count, const struct wined3d_shader_signature *output_signature, const struct wined3d_shader_reg_maps *reg_maps_out, const char *output_variable_name, BOOL rasterizer_setup)
Definition: glsl_shader.c:7195
unsigned int output_vertex_count
struct wined3d_hull_shader::@357 phases
unsigned int temporary_count

Referenced by find_glsl_hull_shader().

◆ shader_glsl_generate_patch_constant_name()

static void shader_glsl_generate_patch_constant_name ( struct wined3d_string_buffer *  buffer,
const struct wined3d_shader_signature_element *  constant,
unsigned int *  user_constant_idx,
const char *  reg_mask 
)
static

Definition at line 7561 of file glsl_shader.c.

7564{
7565 if (!constant->sysval_semantic)
7566 {
7567 shader_addline(buffer, "user_patch_constant[%u]%s", (*user_constant_idx)++, reg_mask);
7568 return;
7569 }
7570
7571 switch (constant->sysval_semantic)
7572 {
7577 shader_addline(buffer, "gl_TessLevelOuter[%u]", constant->semantic_idx);
7578 break;
7581 shader_addline(buffer, "gl_TessLevelInner[%u]", constant->semantic_idx);
7582 break;
7583 default:
7584 FIXME("Unhandled sysval semantic %#x.\n", constant->sysval_semantic);
7585 shader_addline(buffer, "vec4(0.0)%s", reg_mask);
7586 }
7587}
@ WINED3D_SV_TESS_FACTOR_QUADINT
@ WINED3D_SV_TESS_FACTOR_QUADEDGE
@ WINED3D_SV_TESS_FACTOR_LINEDET
@ WINED3D_SV_TESS_FACTOR_TRIINT
@ WINED3D_SV_TESS_FACTOR_TRIEDGE
@ WINED3D_SV_TESS_FACTOR_LINEDEN

Referenced by shader_glsl_generate_patch_constant_setup().

◆ shader_glsl_generate_patch_constant_setup()

static void shader_glsl_generate_patch_constant_setup ( struct wined3d_string_buffer *  buffer,
const struct wined3d_shader_signature *  signature,
BOOL  input_setup 
)
static

Definition at line 7589 of file glsl_shader.c.

7591{
7592 unsigned int i, register_count, user_constant_index, user_constant_count;
7593
7594 register_count = user_constant_count = 0;
7595 for (i = 0; i < signature->element_count; ++i)
7596 {
7597 const struct wined3d_shader_signature_element *constant = &signature->elements[i];
7598 register_count = max(constant->register_idx + 1, register_count);
7599 if (!constant->sysval_semantic)
7600 ++user_constant_count;
7601 }
7602
7603 if (user_constant_count)
7604 shader_addline(buffer, "patch %s vec4 user_patch_constant[%u];\n",
7605 input_setup ? "in" : "out", user_constant_count);
7606 if (input_setup)
7607 shader_addline(buffer, "vec4 vpc[%u];\n", register_count);
7608
7609 shader_addline(buffer, "void setup_patch_constant_%s()\n{\n", input_setup ? "input" : "output");
7610 for (i = 0, user_constant_index = 0; i < signature->element_count; ++i)
7611 {
7612 const struct wined3d_shader_signature_element *constant = &signature->elements[i];
7613 char reg_mask[6];
7614
7615 shader_glsl_write_mask_to_str(constant->mask, reg_mask);
7616
7617 if (input_setup)
7618 shader_addline(buffer, "vpc[%u]%s", constant->register_idx, reg_mask);
7619 else
7620 shader_glsl_generate_patch_constant_name(buffer, constant, &user_constant_index, reg_mask);
7621
7622 shader_addline(buffer, " = ");
7623
7624 if (input_setup)
7625 shader_glsl_generate_patch_constant_name(buffer, constant, &user_constant_index, reg_mask);
7626 else
7627 shader_addline(buffer, "hs_out[%u]%s", constant->register_idx, reg_mask);
7628
7629 shader_addline(buffer, ";\n");
7630 }
7631 shader_addline(buffer, "}\n");
7632}
static void shader_glsl_generate_patch_constant_name(struct wined3d_string_buffer *buffer, const struct wined3d_shader_signature_element *constant, unsigned int *user_constant_idx, const char *reg_mask)
Definition: glsl_shader.c:7561

Referenced by shader_glsl_generate_domain_shader(), and shader_glsl_generate_hull_shader().

◆ shader_glsl_generate_ps_epilogue()

static void shader_glsl_generate_ps_epilogue ( const struct wined3d_gl_info *  gl_info,
struct wined3d_string_buffer *  buffer,
const struct wined3d_shader *  shader,
const struct ps_compile_args *  args,
struct wined3d_string_buffer_list *  string_buffers 
)
static

Definition at line 7807 of file glsl_shader.c.

7810{
7811 const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
7812
7813 /* Pixel shaders < 2.0 place the resulting color in R0 implicitly. */
7814 if (reg_maps->shader_version.major < 2)
7815 shader_addline(buffer, "%s[0] = R0;\n", get_fragment_output(gl_info));
7816
7817 if (args->srgb_correction)
7819
7820 /* SM < 3 does not replace the fog stage. */
7821 if (reg_maps->shader_version.major < 3)
7823
7824 shader_glsl_generate_alpha_test(buffer, gl_info, args->alpha_test_func + 1);
7825
7826 if (reg_maps->sample_mask)
7827 shader_addline(buffer, "gl_SampleMask[0] = floatBitsToInt(sample_mask);\n");
7828
7829 if (reg_maps->stencil_ref)
7830 shader_addline(buffer, "gl_FragStencilRefARB = floatBitsToInt(stencil_ref);\n");
7831
7832 if (!use_legacy_fragment_output(gl_info))
7833 shader_glsl_generate_color_output(buffer, gl_info, shader, args, string_buffers);
7834}
static void shader_glsl_generate_color_output(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const struct wined3d_shader *shader, const struct ps_compile_args *args, struct wined3d_string_buffer_list *string_buffers)
Definition: glsl_shader.c:7758

Referenced by shader_glsl_generate_fragment_shader(), and shader_glsl_generate_shader_epilogue().

◆ shader_glsl_generate_shader_epilogue()

static void shader_glsl_generate_shader_epilogue ( const struct wined3d_shader_context *  ctx)
static

Definition at line 8611 of file glsl_shader.c.

8612{
8613 const struct shader_glsl_ctx_priv *priv = ctx->backend_data;
8614 const struct wined3d_gl_info *gl_info = priv->gl_info;
8615 struct wined3d_string_buffer *buffer = ctx->buffer;
8616 const struct wined3d_shader *shader = ctx->shader;
8617
8618 switch (shader->reg_maps.shader_version.type)
8619 {
8622 break;
8625 break;
8628 break;
8631 break;
8632 default:
8633 FIXME("Unhandled shader type %#x.\n", shader->reg_maps.shader_version.type);
8634 break;
8635 }
8636}
static void shader_glsl_generate_ds_epilogue(const struct wined3d_gl_info *gl_info, struct wined3d_string_buffer *buffer, const struct wined3d_shader *shader, const struct ds_compile_args *args)
Definition: glsl_shader.c:8404
static void shader_glsl_generate_vs_epilogue(const struct wined3d_gl_info *gl_info, struct wined3d_string_buffer *buffer, const struct wined3d_shader *shader, const struct vs_compile_args *args)
Definition: glsl_shader.c:8109
const struct ds_compile_args * cur_ds_args
Definition: glsl_shader.c:271

Referenced by shader_glsl_conditional_op(), and shader_glsl_ret().

◆ shader_glsl_generate_shader_phase()

static HRESULT shader_glsl_generate_shader_phase ( const struct wined3d_shader *  shader,
struct wined3d_string_buffer *  buffer,
const struct wined3d_shader_reg_maps *  reg_maps,
struct shader_glsl_ctx_priv *  priv_ctx,
const struct wined3d_shader_phase *  phase,
const char *  phase_name,
unsigned  phase_idx 
)
static

Definition at line 8282 of file glsl_shader.c.

8286{
8287 unsigned int i;
8288 HRESULT hr;
8289
8290 shader_addline(buffer, "void hs_%s_phase%u(%s)\n{\n",
8291 phase_name, phase_idx, phase->instance_count ? "int phase_instance_id" : "");
8292 for (i = 0; i < phase->temporary_count; ++i)
8293 shader_addline(buffer, "vec4 R%u;\n", i);
8294 hr = shader_generate_code(shader, buffer, reg_maps, priv_ctx, phase->start, phase->end);
8295 shader_addline(buffer, "}\n");
8296 return hr;
8297}
unsigned int instance_count

Referenced by shader_glsl_generate_hull_shader().

◆ shader_glsl_generate_shader_phase_invocation()

static void shader_glsl_generate_shader_phase_invocation ( struct wined3d_string_buffer *  buffer,
const struct wined3d_shader_phase *  phase,
const char *  phase_name,
unsigned int  phase_idx 
)
static

Definition at line 8299 of file glsl_shader.c.

8301{
8302 if (phase->instance_count)
8303 {
8304 shader_addline(buffer, "for (int i = 0; i < %u; ++i)\n{\n", phase->instance_count);
8305 shader_addline(buffer, "hs_%s_phase%u(i);\n", phase_name, phase_idx);
8306 shader_addline(buffer, "}\n");
8307 }
8308 else
8309 {
8310 shader_addline(buffer, "hs_%s_phase%u();\n", phase_name, phase_idx);
8311 }
8312}

Referenced by shader_glsl_generate_hull_shader().

◆ shader_glsl_generate_sm4_output_setup()

static void shader_glsl_generate_sm4_output_setup ( struct shader_glsl_priv *  priv,
const struct wined3d_shader *  shader,
unsigned int  input_count,
const struct wined3d_gl_info *  gl_info,
BOOL  rasterizer_setup,
const uint32_t *  interpolation_mode 
)
static

Definition at line 7535 of file glsl_shader.c.

7538{
7539 const char *prefix = shader_glsl_get_prefix(shader->reg_maps.shader_version.type);
7541
7542 if (rasterizer_setup)
7543 input_count = min(vec4_varyings(4, gl_info), input_count);
7544
7545 if (input_count)
7546 shader_glsl_declare_shader_outputs(gl_info, buffer, input_count, rasterizer_setup, interpolation_mode);
7547
7548 shader_addline(buffer, "void setup_%s_output(in vec4 outputs[%u])\n{\n",
7549 prefix, shader->limits->packed_output);
7550
7551 if (rasterizer_setup)
7553 NULL, input_count, &shader->output_signature, &shader->reg_maps, FALSE);
7554 else
7555 shader_glsl_setup_sm4_shader_output(priv, input_count, &shader->output_signature,
7556 &shader->reg_maps, "shader_out", rasterizer_setup);
7557
7558 shader_addline(buffer, "}\n");
7559}
static void shader_glsl_setup_sm3_rasterizer_input(struct shader_glsl_priv *priv, const struct wined3d_gl_info *gl_info, const unsigned int *map, const struct wined3d_shader_signature *input_signature, const struct wined3d_shader_reg_maps *reg_maps_in, unsigned int input_count, const struct wined3d_shader_signature *output_signature, const struct wined3d_shader_reg_maps *reg_maps_out, BOOL per_vertex_point_size)
Definition: glsl_shader.c:7247
static void shader_glsl_declare_shader_outputs(const struct wined3d_gl_info *gl_info, struct wined3d_string_buffer *buffer, unsigned int element_count, BOOL rasterizer_setup, const uint32_t *interpolation_mode)
Definition: glsl_shader.c:2219

Referenced by shader_glsl_generate_domain_shader(), shader_glsl_generate_geometry_shader(), and shader_glsl_generate_vertex_shader().

◆ shader_glsl_generate_srgb_write_correction()

static void shader_glsl_generate_srgb_write_correction ( struct wined3d_string_buffer *  buffer,
const struct wined3d_gl_info *  gl_info 
)
static

Definition at line 7634 of file glsl_shader.c.

7636{
7637 const char *output = get_fragment_output(gl_info);
7638
7639 shader_addline(buffer, "tmp0.xyz = pow(%s[0].xyz, vec3(srgb_const0.x));\n", output);
7640 shader_addline(buffer, "tmp0.xyz = tmp0.xyz * vec3(srgb_const0.y) - vec3(srgb_const0.z);\n");
7641 shader_addline(buffer, "tmp1.xyz = %s[0].xyz * vec3(srgb_const0.w);\n", output);
7642 shader_addline(buffer, "bvec3 srgb_compare = lessThan(%s[0].xyz, vec3(srgb_const1.x));\n", output);
7643 shader_addline(buffer, "%s[0].xyz = mix(tmp0.xyz, tmp1.xyz, vec3(srgb_compare));\n", output);
7644 shader_addline(buffer, "%s[0] = clamp(%s[0], 0.0, 1.0);\n", output, output);
7645}

Referenced by shader_glsl_generate_ffp_fragment_shader(), and shader_glsl_generate_ps_epilogue().

◆ shader_glsl_generate_stream_output_setup()

static void shader_glsl_generate_stream_output_setup ( struct wined3d_string_buffer *  buffer,
const struct wined3d_shader *  shader 
)
static

Definition at line 7462 of file glsl_shader.c.

7464{
7465 const struct wined3d_stream_output_desc *so_desc = shader->u.gs.so_desc;
7466 unsigned int i, register_idx, component_idx;
7467
7468 shader_addline(buffer, "out shader_in_out\n{\n");
7469 for (i = 0; i < so_desc->element_count; ++i)
7470 {
7471 const struct wined3d_stream_output_element *e = &so_desc->elements[i];
7472
7473 if (e->stream_idx)
7474 {
7475 FIXME("Unhandled stream %u.\n", e->stream_idx);
7476 continue;
7477 }
7478 if (!e->semantic_name)
7479 continue;
7481 continue;
7482
7483 if (component_idx || e->component_count != 4)
7484 {
7485 if (e->component_count == 1)
7486 shader_addline(buffer, "float");
7487 else
7488 shader_addline(buffer, "vec%u", e->component_count);
7489
7490 shader_addline(buffer, " reg%u_%u_%u;\n",
7491 register_idx, component_idx, component_idx + e->component_count - 1);
7492 }
7493 else
7494 {
7495 shader_addline(buffer, "vec4 reg%u;\n", register_idx);
7496 }
7497 }
7498 shader_addline(buffer, "} shader_out;\n");
7499
7500 shader_addline(buffer, "void setup_gs_output(in vec4 outputs[%u])\n{\n",
7501 shader->limits->packed_output);
7502 for (i = 0; i < so_desc->element_count; ++i)
7503 {
7504 const struct wined3d_stream_output_element *e = &so_desc->elements[i];
7505
7506 if (e->stream_idx)
7507 {
7508 FIXME("Unhandled stream %u.\n", e->stream_idx);
7509 continue;
7510 }
7511 if (!e->semantic_name)
7512 continue;
7514 continue;
7515
7516 if (component_idx || e->component_count != 4)
7517 {
7518 DWORD write_mask;
7519 char str_mask[6];
7520
7521 write_mask = wined3d_mask_from_size(e->component_count) << component_idx;
7522 shader_glsl_write_mask_to_str(write_mask, str_mask);
7523 shader_addline(buffer, "shader_out.reg%u_%u_%u = outputs[%u]%s;\n",
7524 register_idx, component_idx, component_idx + e->component_count - 1,
7525 register_idx, str_mask);
7526 }
7527 else
7528 {
7529 shader_addline(buffer, "shader_out.reg%u = outputs[%u];\n", register_idx, register_idx);
7530 }
7531 }
7532 shader_addline(buffer, "}\n");
7533}
BOOL shader_get_stream_output_register_info(const struct wined3d_shader *shader, const struct wined3d_stream_output_element *so_element, unsigned int *register_idx, unsigned int *component_idx)
Definition: shader.c:2117
unsigned int element_count
Definition: wined3d.h:2122
const struct wined3d_stream_output_element * elements
Definition: wined3d.h:2121

Referenced by shader_glsl_generate_geometry_shader().

◆ shader_glsl_generate_transform_feedback_varyings()

static BOOL shader_glsl_generate_transform_feedback_varyings ( struct wined3d_string_buffer *  buffer,
const char **  varyings,
unsigned int *  varying_count,
char *  strings,
unsigned int *  strings_length,
GLenum  buffer_mode,
struct wined3d_shader *  shader 
)
static

Definition at line 1046 of file glsl_shader.c.

1049{
1050 const struct wined3d_stream_output_desc *so_desc = shader->u.gs.so_desc;
1051 unsigned int buffer_idx, count, length, highest_output_slot, stride;
1052 unsigned int i, register_idx, component_idx;
1053 BOOL have_varyings_to_record = FALSE;
1054
1055 count = length = 0;
1056 highest_output_slot = 0;
1057 for (buffer_idx = 0; buffer_idx < WINED3D_MAX_STREAM_OUTPUT_BUFFERS; ++buffer_idx)
1058 {
1059 stride = 0;
1060
1061 for (i = 0; i < so_desc->element_count; ++i)
1062 {
1063 const struct wined3d_stream_output_element *e = &so_desc->elements[i];
1064
1065 highest_output_slot = max(highest_output_slot, e->output_slot);
1066 if (e->output_slot != buffer_idx)
1067 continue;
1068
1069 if (e->stream_idx)
1070 {
1071 FIXME("Unhandled stream %u.\n", e->stream_idx);
1072 continue;
1073 }
1074
1075 stride += e->component_count;
1076
1077 if (!e->semantic_name)
1078 {
1080 &strings, &length, buffer, e->component_count);
1081 continue;
1082 }
1083
1085 continue;
1086
1087 if (component_idx || e->component_count != 4)
1088 {
1090 {
1091 FIXME("Unsupported component range %u-%u.\n", component_idx, e->component_count);
1093 &strings, &length, buffer, e->component_count);
1094 continue;
1095 }
1096
1097 string_buffer_sprintf(buffer, "shader_in_out.reg%u_%u_%u",
1098 register_idx, component_idx, component_idx + e->component_count - 1);
1100 }
1101 else
1102 {
1103 string_buffer_sprintf(buffer, "shader_in_out.reg%u", register_idx);
1105 }
1106
1107 have_varyings_to_record = TRUE;
1108 }
1109
1110 if (buffer_idx < so_desc->buffer_stride_count
1111 && stride < so_desc->buffer_strides[buffer_idx] / 4)
1112 {
1113 unsigned int component_count = so_desc->buffer_strides[buffer_idx] / 4 - stride;
1116 }
1117
1118 if (highest_output_slot <= buffer_idx)
1119 break;
1120
1121 if (buffer_mode == GL_INTERLEAVED_ATTRIBS)
1122 {
1123 string_buffer_sprintf(buffer, "gl_NextBuffer");
1125 }
1126 }
1127
1128 if (varying_count)
1129 *varying_count = count;
1130 if (strings_length)
1131 *strings_length = length;
1132
1133 return have_varyings_to_record;
1134}
#define GL_INTERLEAVED_ATTRIBS
Definition: glext.h:555
static void append_transform_feedback_skip_components(const char **varyings, unsigned int *varying_count, char **strings, unsigned int *strings_length, struct wined3d_string_buffer *buffer, unsigned int component_count)
Definition: glsl_shader.c:1028
unsigned int buffer_strides[WINED3D_MAX_STREAM_OUTPUT_BUFFERS]
Definition: wined3d.h:2123
unsigned int rasterizer_stream_idx
Definition: wined3d.h:2125
#define WINED3D_NO_RASTERIZER_STREAM
Definition: wined3d.h:1577
#define WINED3D_MAX_STREAM_OUTPUT_BUFFERS
Definition: wined3d.h:1576

Referenced by shader_glsl_init_transform_feedback().

◆ shader_glsl_generate_vertex_shader()

static GLuint shader_glsl_generate_vertex_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
const struct wined3d_shader *  shader,
const struct vs_compile_args *  args 
)
static

Definition at line 8167 of file glsl_shader.c.

8169{
8170 struct wined3d_string_buffer_list *string_buffers = &priv->string_buffers;
8171 const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
8172 const struct wined3d_shader_version *version = &reg_maps->shader_version;
8173 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
8175 struct shader_glsl_ctx_priv priv_ctx;
8176 GLuint shader_id;
8177 unsigned int i;
8178
8179 if (priv->use_vkd3d)
8181
8182 memset(&priv_ctx, 0, sizeof(priv_ctx));
8183 priv_ctx.gl_info = gl_info;
8184 priv_ctx.cur_vs_args = args;
8185 priv_ctx.string_buffers = string_buffers;
8186
8188
8190 if (gl_info->supported[ARB_DRAW_INSTANCED])
8191 shader_addline(buffer, "#extension GL_ARB_draw_instanced : enable\n");
8193 shader_addline(buffer, "#extension GL_ARB_explicit_attrib_location : enable\n");
8195 shader_addline(buffer, "#extension GL_ARB_shader_viewport_layer_array : enable\n");
8196
8197 /* Base Declarations */
8198 shader_generate_glsl_declarations(context_gl, buffer, shader, reg_maps, &priv_ctx);
8199
8200 for (i = 0; i < shader->input_signature.element_count; ++i)
8202
8203 if (args->point_size && !shader->reg_maps.point_size && reg_maps->shader_version.major < 4)
8204 {
8205 shader_addline(buffer, "uniform struct\n{\n");
8206 shader_addline(buffer, " float size;\n");
8207 shader_addline(buffer, " float size_min;\n");
8208 shader_addline(buffer, " float size_max;\n");
8209 shader_addline(buffer, "} ffp_point;\n");
8210 }
8211
8213 {
8214 if (args->clip_enabled)
8215 shader_addline(buffer, "uniform vec4 clip_planes[%u];\n", gl_info->limits.user_clip_distances);
8216
8217 if (version->major < 3)
8218 {
8219 declare_out_varying(gl_info, buffer, args->flatshading, "vec4 ffp_varying_diffuse;\n");
8220 declare_out_varying(gl_info, buffer, args->flatshading, "vec4 ffp_varying_specular;\n");
8221 declare_out_varying(gl_info, buffer, FALSE, "vec4 ffp_varying_texcoord[%u];\n", WINED3D_MAX_FFP_TEXTURES);
8222 declare_out_varying(gl_info, buffer, FALSE, "float ffp_varying_fogcoord;\n");
8223 }
8224 }
8225
8226 if (version->major < 4)
8227 shader_addline(buffer, "void setup_vs_output(in vec4[%u]);\n", shader->limits->packed_output);
8228
8229 if (args->next_shader_type == WINED3D_SHADER_TYPE_PIXEL && !gl_info->supported[ARB_CLIP_CONTROL])
8230 shader_addline(buffer, "uniform vec4 pos_fixup;\n");
8231
8232 if (reg_maps->shader_version.major >= 4)
8233 shader_glsl_generate_sm4_output_setup(priv, shader, args->next_shader_input_count,
8234 gl_info, args->next_shader_type == WINED3D_SHADER_TYPE_PIXEL, args->interpolation_mode);
8235
8236 shader_addline(buffer, "void main()\n{\n");
8237
8238 if (reg_maps->input_rel_addressing)
8239 {
8240 unsigned int highest_input_register = wined3d_log2i(reg_maps->input_registers);
8241 shader_addline(buffer, "vec4 vs_in[%u];\n", highest_input_register + 1);
8242 for (i = 0; i < shader->input_signature.element_count; ++i)
8243 {
8244 const struct wined3d_shader_signature_element *e = &shader->input_signature.elements[i];
8245 shader_addline(buffer, "vs_in[%u] = vs_in%u;\n", e->register_idx, e->register_idx);
8246 }
8247 }
8248
8249 if (FAILED(shader_generate_code(shader, buffer, reg_maps, &priv_ctx, NULL, NULL)))
8250 return 0;
8251
8252 /* In SM4+ the shader epilogue is generated by the "ret" instruction. */
8253 if (reg_maps->shader_version.major < 4)
8255
8256 shader_addline(buffer, "}\n");
8257
8258 shader_id = GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER));
8259 TRACE("Compiling shader object %u.\n", shader_id);
8260 shader_glsl_compile(gl_info, shader_id, buffer->buffer);
8261
8262 return shader_id;
8263}
static void shader_glsl_declare_generic_vertex_attribute(struct wined3d_string_buffer *buffer, const struct wined3d_gl_info *gl_info, const struct wined3d_shader_signature_element *e)
Definition: glsl_shader.c:2332
@ ARB_DRAW_INSTANCED
Definition: wined3d_gl.h:74
@ ARB_SHADER_VIEWPORT_LAYER_ARRAY
Definition: wined3d_gl.h:109

Referenced by find_glsl_vertex_shader().

◆ shader_glsl_generate_vkd3d_shader()

static GLuint shader_glsl_generate_vkd3d_shader ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
const struct wined3d_shader *  shader,
GLenum  gl_shader_type 
)
static

Definition at line 707 of file glsl_shader.c.

709{
710 const struct wined3d_shader_version *version = &shader->reg_maps.shader_version;
711 struct vkd3d_shader_combined_resource_sampler *combined_samplers;
712 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
714 unsigned int binding_count, combined_sampler_count;
716 const struct wined3d_stream_output_desc *so_desc;
717 struct vkd3d_shader_resource_binding *bindings;
719 struct vkd3d_shader_code glsl;
720 GLuint shader_id;
721 char *messages;
722 int ret;
723
724 static const struct vkd3d_shader_compile_option compile_options[] =
725 {
727 };
728
729 if (version->type == WINED3D_SHADER_TYPE_GEOMETRY && (so_desc = shader->u.gs.so_desc))
730 {
732 xfb_info.next = NULL;
733 xfb_info.elements = (const struct vkd3d_shader_transform_feedback_element *)so_desc->elements;
734 xfb_info.element_count = so_desc->element_count;
735 xfb_info.buffer_strides = so_desc->buffer_strides;
736 xfb_info.buffer_stride_count = so_desc->buffer_stride_count;
737
738 interface_info.next = &xfb_info;
739 }
740 else
741 {
743 }
744
745 if (!(bindings = create_resource_bindings(gl_info, version->type, &binding_count)))
746 {
747 ERR("Failed to create resource bindings.\n");
748 return 0;
749 }
750
751 if (!(combined_samplers = create_combined_resource_sampler_bindings(context_gl, shader, &combined_sampler_count)))
752 {
753 ERR("Failed to create combined sampler bindings.\n");
754 free(bindings);
755 return 0;
756 }
757
759 interface_info.bindings = bindings;
760 interface_info.binding_count = binding_count;
761 interface_info.push_constant_buffers = NULL;
762 interface_info.push_constant_buffer_count = 0;
763 interface_info.combined_samplers = combined_samplers;
764 interface_info.combined_sampler_count = combined_sampler_count;
765 interface_info.uav_counters = NULL;
766 interface_info.uav_counter_count = 0;
767
769 info.next = &interface_info;
770 if (shader->source_type == VKD3D_SHADER_SOURCE_D3D_BYTECODE)
771 {
772 info.source.code = shader->function;
773 info.source.size = shader->functionLength;
774 }
775 else
776 {
777 info.source.code = shader->byte_code;
778 info.source.size = shader->byte_code_size;
779 }
780 info.source_type = shader->source_type;
781 info.target_type = VKD3D_SHADER_TARGET_GLSL;
782 info.options = compile_options;
783 info.option_count = ARRAY_SIZE(compile_options);
784 info.log_level = VKD3D_SHADER_LOG_WARNING;
785 info.source_name = NULL;
786
788 if (messages && *messages && FIXME_ON(d3d_shader))
789 {
790 const char *ptr, *end, *line;
791
792 FIXME("Shader log:\n");
793 ptr = messages;
794 end = ptr + strlen(ptr);
795 while ((line = wined3d_get_line(&ptr, end)))
796 {
797 FIXME(" %.*s", (int)(ptr - line), line);
798 }
799 FIXME("\n");
800 }
802 free(combined_samplers);
803 free(bindings);
804
805 if (ret < 0)
806 {
807 ERR("Failed to compile shader, ret %d.\n", ret);
808 return 0;
809 }
810
811 if (!(shader_id = GL_EXTCALL(glCreateShader(gl_shader_type))))
812 {
813 ERR("Failed to create shader.\n");
815 return 0;
816 }
817
818 TRACE("Compiling shader object %u.\n", shader_id);
819 GL_EXTCALL(glShaderSource(shader_id, 1, (const GLchar **)&glsl.code, (const GLint *)&glsl.size));
820 checkGLcall("glShaderSource");
821 GL_EXTCALL(glCompileShader(shader_id));
822 checkGLcall("glCompileShader");
823 print_glsl_info_log(gl_info, shader_id, FALSE);
824
826
827 return shader_id;
828}
char GLchar
Definition: glext.h:5493
static struct vkd3d_shader_combined_resource_sampler * create_combined_resource_sampler_bindings(const struct wined3d_context_gl *context_gl, const struct wined3d_shader *shader, unsigned int *count)
Definition: glsl_shader.c:661
static struct vkd3d_shader_resource_binding * create_resource_bindings(const struct wined3d_gl_info *gl_info, enum wined3d_shader_type shader_type, unsigned int *count)
Definition: glsl_shader.c:634
enum api function
Definition: notification.c:71
struct interface_info * next
Definition: dhcpd.h:231
unsigned int buffer_stride_count
Definition: wined3d.h:2124
@ VKD3D_SHADER_COMPILE_OPTION_API_VERSION
Definition: vkd3d_shader.h:279
VKD3D_SHADER_API void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *code)
@ VKD3D_SHADER_SOURCE_D3D_BYTECODE
@ VKD3D_SHADER_LOG_WARNING
@ VKD3D_SHADER_STRUCTURE_TYPE_TRANSFORM_FEEDBACK_INFO
Definition: vkd3d_shader.h:78
@ VKD3D_SHADER_STRUCTURE_TYPE_COMPILE_INFO
Definition: vkd3d_shader.h:68
@ VKD3D_SHADER_STRUCTURE_TYPE_INTERFACE_INFO
Definition: vkd3d_shader.h:70
@ VKD3D_SHADER_API_VERSION_1_6
Definition: vkd3d_shader.h:51
VKD3D_SHADER_API int vkd3d_shader_compile(const struct vkd3d_shader_compile_info *compile_info, struct vkd3d_shader_code *out, char **messages)
@ VKD3D_SHADER_TARGET_GLSL
VKD3D_SHADER_API void vkd3d_shader_free_messages(char *messages)

Referenced by shader_glsl_generate_compute_shader(), shader_glsl_generate_domain_shader(), shader_glsl_generate_fragment_shader(), shader_glsl_generate_geometry_shader(), shader_glsl_generate_hull_shader(), and shader_glsl_generate_vertex_shader().

◆ shader_glsl_generate_vs3_rasterizer_input_setup()

static GLuint shader_glsl_generate_vs3_rasterizer_input_setup ( struct shader_glsl_priv *  priv,
const struct wined3d_shader *  vs,
const struct wined3d_shader *  ps,
BOOL  per_vertex_point_size,
BOOL  flatshading,
const struct wined3d_gl_info *  gl_info 
)
static

Definition at line 7318 of file glsl_shader.c.

7321{
7322 const BOOL legacy_syntax = needs_legacy_glsl_syntax(gl_info);
7323 DWORD ps_major = ps ? ps->reg_maps.shader_version.major : 0;
7325 const char *semantic_name;
7326 UINT semantic_idx;
7327 char reg_mask[6];
7328 unsigned int i;
7329 GLuint ret;
7330
7332
7334
7335 shader_addline(buffer, "invariant gl_Position;\n");
7336
7337 if (per_vertex_point_size)
7338 {
7339 shader_addline(buffer, "uniform struct\n{\n");
7340 shader_addline(buffer, " float size_min;\n");
7341 shader_addline(buffer, " float size_max;\n");
7342 shader_addline(buffer, "} ffp_point;\n");
7343 }
7344
7345 if (ps_major < 3)
7346 {
7347 DWORD colors_written_mask[2] = {0};
7348 DWORD texcoords_written_mask[WINED3D_MAX_FFP_TEXTURES] = {0};
7349
7350 if (!legacy_syntax)
7351 {
7352 declare_out_varying(gl_info, buffer, flatshading, "vec4 ffp_varying_diffuse;\n");
7353 declare_out_varying(gl_info, buffer, flatshading, "vec4 ffp_varying_specular;\n");
7354 declare_out_varying(gl_info, buffer, FALSE, "vec4 ffp_varying_texcoord[%u];\n", WINED3D_MAX_FFP_TEXTURES);
7355 declare_out_varying(gl_info, buffer, FALSE, "float ffp_varying_fogcoord;\n");
7356 }
7357
7358 shader_addline(buffer, "void setup_vs_output(in vec4 outputs[%u])\n{\n", vs->limits->packed_output);
7359
7360 for (i = 0; i < vs->output_signature.element_count; ++i)
7361 {
7362 const struct wined3d_shader_signature_element *output = &vs->output_signature.elements[i];
7363 DWORD write_mask;
7364
7365 if (!(vs->reg_maps.output_registers & (1u << output->register_idx)))
7366 continue;
7367
7368 semantic_name = output->semantic_name;
7369 semantic_idx = output->semantic_idx;
7370 write_mask = output->mask;
7371 shader_glsl_write_mask_to_str(write_mask, reg_mask);
7372
7374 {
7375 if (legacy_syntax)
7376 shader_addline(buffer, "gl_Front%sColor%s = outputs[%u]%s;\n",
7377 semantic_idx ? "Secondary" : "", reg_mask, output->register_idx, reg_mask);
7378 else
7379 shader_addline(buffer, "ffp_varying_%s%s = clamp(outputs[%u]%s, 0.0, 1.0);\n",
7380 semantic_idx ? "specular" : "diffuse", reg_mask, output->register_idx, reg_mask);
7381
7382 colors_written_mask[semantic_idx] = write_mask;
7383 }
7385 {
7386 shader_addline(buffer, "gl_Position%s = outputs[%u]%s;\n",
7387 reg_mask, output->register_idx, reg_mask);
7388 }
7390 {
7392 {
7393 shader_addline(buffer, "%s[%u]%s = outputs[%u]%s;\n",
7394 legacy_syntax ? "gl_TexCoord" : "ffp_varying_texcoord",
7395 semantic_idx, reg_mask, output->register_idx, reg_mask);
7396 texcoords_written_mask[semantic_idx] = write_mask;
7397 }
7398 }
7399 else if (shader_match_semantic(semantic_name, WINED3D_DECL_USAGE_PSIZE) && per_vertex_point_size)
7400 {
7401 shader_addline(buffer, "gl_PointSize = clamp(outputs[%u].%c, "
7402 "ffp_point.size_min, ffp_point.size_max);\n", output->register_idx, reg_mask[1]);
7403 }
7405 {
7406 shader_addline(buffer, "%s = outputs[%u].%c;\n",
7407 legacy_syntax ? "gl_FogFragCoord" : "ffp_varying_fogcoord",
7408 output->register_idx, reg_mask[1]);
7409 }
7410 }
7411
7412 for (i = 0; i < 2; ++i)
7413 {
7414 if (colors_written_mask[i] != WINED3DSP_WRITEMASK_ALL)
7415 {
7416 shader_glsl_write_mask_to_str(~colors_written_mask[i] & WINED3DSP_WRITEMASK_ALL, reg_mask);
7417 if (!i)
7418 shader_addline(buffer, "%s%s = vec4(1.0)%s;\n",
7419 legacy_syntax ? "gl_FrontColor" : "ffp_varying_diffuse",
7420 reg_mask, reg_mask);
7421 else
7422 shader_addline(buffer, "%s%s = vec4(0.0)%s;\n",
7423 legacy_syntax ? "gl_FrontSecondaryColor" : "ffp_varying_specular",
7424 reg_mask, reg_mask);
7425 }
7426 }
7427 for (i = 0; i < WINED3D_MAX_FFP_TEXTURES; ++i)
7428 {
7429 if (ps && !(ps->reg_maps.texcoord & (1u << i)))
7430 continue;
7431
7432 if (texcoords_written_mask[i] != WINED3DSP_WRITEMASK_ALL)
7433 {
7434 if (!shader_glsl_full_ffp_varyings(gl_info) && !texcoords_written_mask[i])
7435 continue;
7436
7437 shader_glsl_write_mask_to_str(~texcoords_written_mask[i] & WINED3DSP_WRITEMASK_ALL, reg_mask);
7438 shader_addline(buffer, "%s[%u]%s = vec4(0.0)%s;\n",
7439 legacy_syntax ? "gl_TexCoord" : "ffp_varying_texcoord", i, reg_mask, reg_mask);
7440 }
7441 }
7442 }
7443 else
7444 {
7445 unsigned int in_count = min(vec4_varyings(ps_major, gl_info), ps->limits->packed_input);
7446
7448 shader_addline(buffer, "void setup_vs_output(in vec4 outputs[%u])\n{\n", vs->limits->packed_output);
7449 shader_glsl_setup_sm3_rasterizer_input(priv, gl_info, ps->u.ps.input_reg_map, &ps->input_signature,
7450 &ps->reg_maps, 0, &vs->output_signature, &vs->reg_maps, per_vertex_point_size);
7451 }
7452
7453 shader_addline(buffer, "}\n");
7454
7455 ret = GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER));
7456 checkGLcall("glCreateShader(GL_VERTEX_SHADER)");
7457 shader_glsl_compile(gl_info, ret, buffer->buffer);
7458
7459 return ret;
7460}
struct wined3d_shader_signature input_signature
@ WINED3D_DECL_USAGE_PSIZE
Definition: wined3d.h:811
@ WINED3D_DECL_USAGE_POSITION
Definition: wined3d.h:807
@ WINED3D_DECL_USAGE_TEXCOORD
Definition: wined3d.h:812
@ WINED3D_DECL_USAGE_FOG
Definition: wined3d.h:818

Referenced by set_glsl_shader_program().

◆ shader_glsl_generate_vs_epilogue()

static void shader_glsl_generate_vs_epilogue ( const struct wined3d_gl_info *  gl_info,
struct wined3d_string_buffer *  buffer,
const struct wined3d_shader *  shader,
const struct vs_compile_args *  args 
)
static

Definition at line 8109 of file glsl_shader.c.

8112{
8113 const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
8114 const BOOL legacy_syntax = needs_legacy_glsl_syntax(gl_info);
8115 unsigned int i;
8116
8117 /* Unpack outputs. */
8118 shader_addline(buffer, "setup_vs_output(vs_out);\n");
8119
8120 /* The D3DRS_FOGTABLEMODE render state defines if the shader-generated fog coord is used
8121 * or if the fragment depth is used. If the fragment depth is used(FOGTABLEMODE != NONE),
8122 * the fog frag coord is thrown away. If the fog frag coord is used, but not written by
8123 * the shader, it is set to 0.0(fully fogged, since start = 1.0, end = 0.0).
8124 */
8125 if (reg_maps->shader_version.major < 3)
8126 {
8127 if (args->fog_src == VS_FOG_Z)
8128 shader_addline(buffer, "%s = gl_Position.z;\n",
8129 legacy_syntax ? "gl_FogFragCoord" : "ffp_varying_fogcoord");
8130 else if (args->fog_src == VS_FOG_W)
8131 shader_addline(buffer, "%s = gl_Position.w;\n",
8132 legacy_syntax ? "gl_FogFragCoord" : "ffp_varying_fogcoord");
8133 else if (!reg_maps->fog)
8134 {
8135 if (reg_maps->output_registers & (1u << (8 + 1)))
8136 shader_addline(buffer, "%s = ffp_varying_specular.w;\n",
8137 legacy_syntax ? "gl_FogFragCoord" : "ffp_varying_fogcoord");
8138 else
8139 shader_addline(buffer, "%s = 0.0;\n",
8140 legacy_syntax ? "gl_FogFragCoord" : "ffp_varying_fogcoord");
8141 }
8142 }
8143
8144 /* We always store the clipplanes without y inversion. */
8145 if (args->clip_enabled)
8146 {
8147 if (legacy_syntax)
8148 shader_addline(buffer, "gl_ClipVertex = gl_Position;\n");
8149 else
8150 for (i = 0; i < gl_info->limits.user_clip_distances; ++i)
8151 shader_addline(buffer, "gl_ClipDistance[%u] = dot(gl_Position, clip_planes[%u]);\n", i, i);
8152 }
8153
8154 if (args->point_size && !shader->reg_maps.point_size)
8155 {
8156 if (reg_maps->shader_version.major >= 4)
8157 shader_addline(buffer, "gl_PointSize = 1.0;\n");
8158 else
8159 shader_addline(buffer, "gl_PointSize = clamp(ffp_point.size, ffp_point.size_min, ffp_point.size_max);\n");
8160 }
8161
8162 if (args->next_shader_type == WINED3D_SHADER_TYPE_PIXEL && !gl_info->supported[ARB_CLIP_CONTROL])
8164}
@ VS_FOG_W
@ VS_FOG_Z

Referenced by shader_glsl_generate_shader_epilogue(), and shader_glsl_generate_vertex_shader().

◆ shader_glsl_get_caps()

static void shader_glsl_get_caps ( const struct wined3d_adapter *  adapter,
struct shader_caps *  caps 
)
static

Definition at line 11371 of file glsl_shader.c.

11372{
11373 const struct wined3d_gl_info *gl_info = &wined3d_adapter_gl_const(adapter)->gl_info;
11374 unsigned int shader_model = shader_glsl_get_shader_model(gl_info);
11375
11376 TRACE("Shader model %u.\n", shader_model);
11377
11378 memset(caps, 0, sizeof(*caps));
11379
11380 caps->vs_version = min(wined3d_settings.max_sm_vs, shader_model);
11381 caps->hs_version = min(wined3d_settings.max_sm_hs, shader_model);
11382 caps->ds_version = min(wined3d_settings.max_sm_ds, shader_model);
11383 caps->gs_version = min(wined3d_settings.max_sm_gs, shader_model);
11384 caps->ps_version = min(wined3d_settings.max_sm_ps, shader_model);
11385 caps->cs_version = min(wined3d_settings.max_sm_cs, shader_model);
11386
11387 caps->vs_version = gl_info->supported[ARB_VERTEX_SHADER] ? caps->vs_version : 0;
11388 caps->ps_version = gl_info->supported[ARB_FRAGMENT_SHADER] ? caps->ps_version : 0;
11389
11390 caps->vs_uniform_count = min(WINED3D_MAX_VS_CONSTS_F, gl_info->limits.glsl_vs_float_constants);
11391 caps->ps_uniform_count = min(WINED3D_MAX_PS_CONSTS_F, gl_info->limits.glsl_ps_float_constants);
11392 caps->varying_count = gl_info->limits.glsl_varyings;
11393
11394 /* FIXME: The following line is card dependent. -8.0 to 8.0 is the
11395 * Direct3D minimum requirement.
11396 *
11397 * Both GL_ARB_fragment_program and GLSL require a "maximum representable magnitude"
11398 * of colors to be 2^10, and 2^32 for other floats. Should we use 1024 here?
11399 *
11400 * The problem is that the refrast clamps temporary results in the shader to
11401 * [-MaxValue;+MaxValue]. If the card's max value is bigger than the one we advertize here,
11402 * then applications may miss the clamping behavior. On the other hand, if it is smaller,
11403 * the shader will generate incorrect results too. Unfortunately, GL deliberately doesn't
11404 * offer a way to query this.
11405 */
11406 if (shader_model >= 4)
11407 caps->ps_1x_max_value = FLT_MAX;
11408 else
11409 caps->ps_1x_max_value = 1024.0f;
11410
11411 /* Ideally we'd only set caps like sRGB writes here if supported by both
11412 * the shader backend and the fragment pipe, but we can get called before
11413 * shader_glsl_alloc(). */
11416 if (shader_glsl_full_ffp_varyings(gl_info))
11418}
#define FLT_MAX
Definition: float.h:37
static unsigned int shader_glsl_get_shader_model(const struct wined3d_gl_info *gl_info)
unsigned int vs_version
unsigned int varying_count
unsigned int cs_version
unsigned int ps_uniform_count
unsigned int hs_version
unsigned int gs_version
unsigned int vs_uniform_count
unsigned int ps_version
unsigned int ds_version
unsigned int max_sm_hs
unsigned int max_sm_vs
unsigned int max_sm_ps
unsigned int max_sm_cs
unsigned int max_sm_ds
unsigned int max_sm_gs
@ ARB_VERTEX_SHADER
Definition: wined3d_gl.h:155
@ ARB_FRAGMENT_SHADER
Definition: wined3d_gl.h:82
#define WINED3D_SHADER_CAP_OUTPUT_INTERPOLATION
#define WINED3D_SHADER_CAP_FULL_FFP_VARYINGS

◆ shader_glsl_get_coord_size()

static void shader_glsl_get_coord_size ( enum wined3d_shader_resource_type  resource_type,
unsigned int *  coord_size,
unsigned int *  deriv_size 
)
static

Definition at line 3598 of file glsl_shader.c.

3600{
3602 || resource_type == WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY;
3603
3604 *coord_size = resource_type_info[resource_type].coord_size;
3605 *deriv_size = *coord_size;
3606 if (is_array)
3607 --(*deriv_size);
3608}
static int is_array(const type_t *t)
Definition: header.h:60

Referenced by shader_glsl_gather4(), and shader_glsl_get_sample_function().

◆ shader_glsl_get_ffp_fragment_op_arg()

static const char * shader_glsl_get_ffp_fragment_op_arg ( struct wined3d_string_buffer *  buffer,
unsigned int  argnum,
unsigned int  stage,
DWORD  arg 
)
static

Definition at line 9448 of file glsl_shader.c.

9450{
9451 const char *ret;
9452
9453 if (arg == ARG_UNUSED)
9454 return "<unused arg>";
9455
9456 switch (arg & WINED3DTA_SELECTMASK)
9457 {
9458 case WINED3DTA_DIFFUSE:
9459 ret = "ffp_varying_diffuse";
9460 break;
9461
9462 case WINED3DTA_CURRENT:
9463 ret = "ret";
9464 break;
9465
9466 case WINED3DTA_TEXTURE:
9467 switch (stage)
9468 {
9469 case 0: ret = "tex0"; break;
9470 case 1: ret = "tex1"; break;
9471 case 2: ret = "tex2"; break;
9472 case 3: ret = "tex3"; break;
9473 case 4: ret = "tex4"; break;
9474 case 5: ret = "tex5"; break;
9475 case 6: ret = "tex6"; break;
9476 case 7: ret = "tex7"; break;
9477 default:
9478 ret = "<invalid texture>";
9479 break;
9480 }
9481 break;
9482
9483 case WINED3DTA_TFACTOR:
9484 ret = "tex_factor";
9485 break;
9486
9487 case WINED3DTA_SPECULAR:
9488 ret = "ffp_varying_specular";
9489 break;
9490
9491 case WINED3DTA_TEMP:
9492 ret = "temp_reg";
9493 break;
9494
9495 case WINED3DTA_CONSTANT:
9496 switch (stage)
9497 {
9498 case 0: ret = "tss_const0"; break;
9499 case 1: ret = "tss_const1"; break;
9500 case 2: ret = "tss_const2"; break;
9501 case 3: ret = "tss_const3"; break;
9502 case 4: ret = "tss_const4"; break;
9503 case 5: ret = "tss_const5"; break;
9504 case 6: ret = "tss_const6"; break;
9505 case 7: ret = "tss_const7"; break;
9506 default:
9507 ret = "<invalid constant>";
9508 break;
9509 }
9510 break;
9511
9512 default:
9513 return "<unhandled arg>";
9514 }
9515
9517 {
9518 shader_addline(buffer, "arg%u = vec4(1.0) - %s;\n", argnum, ret);
9519 if (argnum == 0)
9520 ret = "arg0";
9521 else if (argnum == 1)
9522 ret = "arg1";
9523 else if (argnum == 2)
9524 ret = "arg2";
9525 }
9526
9528 {
9529 shader_addline(buffer, "arg%u = vec4(%s.w);\n", argnum, ret);
9530 if (argnum == 0)
9531 ret = "arg0";
9532 else if (argnum == 1)
9533 ret = "arg1";
9534 else if (argnum == 2)
9535 ret = "arg2";
9536 }
9537
9538 return ret;
9539}
#define WINED3DTA_SPECULAR
Definition: wined3d.h:885
#define WINED3DTA_COMPLEMENT
Definition: wined3d.h:888
#define WINED3DTA_ALPHAREPLICATE
Definition: wined3d.h:889
#define ARG_UNUSED

Referenced by shader_glsl_ffp_fragment_op().

◆ shader_glsl_get_prefix()

◆ shader_glsl_get_register_name()

static void shader_glsl_get_register_name ( const struct wined3d_shader_register *  reg,
enum wined3d_data_type  data_type,
struct wined3d_string_buffer *  register_name,
BOOL *  is_swizzled,
const struct wined3d_shader_context *  ctx 
)
static

Writes the GLSL variable name that corresponds to the register that the DX opcode parameter is trying to access

Definition at line 2858 of file glsl_shader.c.

2861{
2862 /* oPos, oFog and oPts in D3D */
2863 static const char * const hwrastout_reg_names[] = {"vs_out[10]", "vs_out[11].x", "vs_out[11].y"};
2864
2865 const struct wined3d_shader *shader = ctx->shader;
2866 const struct wined3d_shader_reg_maps *reg_maps = ctx->reg_maps;
2867 const struct wined3d_shader_version *version = &reg_maps->shader_version;
2868 const struct shader_glsl_ctx_priv *priv = ctx->backend_data;
2869 const char *prefix = shader_glsl_get_prefix(version->type);
2870 const struct wined3d_gl_info *gl_info = priv->gl_info;
2871 struct glsl_src_param rel_param0, rel_param1;
2872
2873 if (reg->idx[0].offset != ~0u && reg->idx[0].rel_addr)
2875 &rel_param0, reg->idx[0].rel_addr->reg.data_type);
2876 if (reg->idx[1].offset != ~0u && reg->idx[1].rel_addr)
2878 &rel_param1, reg->idx[1].rel_addr->reg.data_type);
2879 if (is_swizzled)
2880 *is_swizzled = FALSE;
2881
2882 switch (reg->type)
2883 {
2884 case WINED3DSPR_TEMP:
2885 string_buffer_sprintf(register_name, "R%u", reg->idx[0].offset);
2886 break;
2887
2888 case WINED3DSPR_INPUT:
2891 {
2892 if (reg->idx[0].rel_addr)
2893 FIXME("VS3 input registers relative addressing.\n");
2894 if (is_swizzled && priv->cur_vs_args->swizzle_map & (1u << reg->idx[0].offset))
2895 *is_swizzled = TRUE;
2896 if (reg->idx[0].rel_addr)
2897 {
2898 string_buffer_sprintf(register_name, "%s_in[%s + %u]",
2899 prefix, rel_param0.param_str, reg->idx[0].offset);
2900 }
2901 else
2902 {
2903 string_buffer_sprintf(register_name, "%s_in%u", prefix, reg->idx[0].offset);
2904 }
2905 break;
2906 }
2907
2911 {
2912 if (reg->idx[0].rel_addr)
2913 {
2914 if (reg->idx[1].rel_addr)
2915 string_buffer_sprintf(register_name, "shader_in[%s + %u].reg[%s + %u]",
2916 rel_param0.param_str, reg->idx[0].offset,
2917 rel_param1.param_str, reg->idx[1].offset);
2918 else
2919 string_buffer_sprintf(register_name, "shader_in[%s + %u].reg[%u]",
2920 rel_param0.param_str, reg->idx[0].offset,
2921 reg->idx[1].offset);
2922 }
2923 else if (reg->idx[1].rel_addr)
2924 string_buffer_sprintf(register_name, "shader_in[%u].reg[%s + %u]", reg->idx[0].offset,
2925 rel_param1.param_str, reg->idx[1].offset);
2926 else
2927 string_buffer_sprintf(register_name, "shader_in[%u].reg[%u]",
2928 reg->idx[0].offset, reg->idx[1].offset);
2929 break;
2930 }
2931
2932 /* pixel shaders >= 3.0 */
2933 if (version->major >= 3)
2934 {
2935 unsigned int idx = shader->u.ps.input_reg_map[reg->idx[0].offset];
2936 unsigned int in_count = vec4_varyings(version->major, gl_info);
2937
2938 if (reg->idx[0].rel_addr)
2939 {
2940 /* Removing a + 0 would be an obvious optimization, but
2941 * OS X doesn't see the NOP operation there. */
2942 if (idx)
2943 {
2944 if (needs_legacy_glsl_syntax(gl_info)
2945 && shader->u.ps.declared_in_count > in_count)
2946 {
2947 string_buffer_sprintf(register_name,
2948 "((%s + %u) > %u ? (%s + %u) > %u ? gl_SecondaryColor : gl_Color : %s_in[%s + %u])",
2949 rel_param0.param_str, idx, in_count - 1, rel_param0.param_str, idx, in_count,
2950 prefix, rel_param0.param_str, idx);
2951 }
2952 else
2953 {
2954 string_buffer_sprintf(register_name, "%s_in[%s + %u]", prefix, rel_param0.param_str, idx);
2955 }
2956 }
2957 else
2958 {
2959 if (needs_legacy_glsl_syntax(gl_info)
2960 && shader->u.ps.declared_in_count > in_count)
2961 {
2962 string_buffer_sprintf(register_name,
2963 "((%s) > %u ? (%s) > %u ? gl_SecondaryColor : gl_Color : %s_in[%s])",
2964 rel_param0.param_str, in_count - 1, rel_param0.param_str, in_count,
2965 prefix, rel_param0.param_str);
2966 }
2967 else
2968 {
2969 string_buffer_sprintf(register_name, "%s_in[%s]", prefix, rel_param0.param_str);
2970 }
2971 }
2972 }
2973 else
2974 {
2975 if (idx == in_count)
2976 string_buffer_sprintf(register_name, "gl_Color");
2977 else if (idx == in_count + 1)
2978 string_buffer_sprintf(register_name, "gl_SecondaryColor");
2979 else
2980 string_buffer_sprintf(register_name, "%s_in[%u]", prefix, idx);
2981 }
2982 }
2983 else
2984 {
2985 if (!reg->idx[0].offset)
2986 string_buffer_sprintf(register_name, "ffp_varying_diffuse");
2987 else
2988 string_buffer_sprintf(register_name, "ffp_varying_specular");
2989 break;
2990 }
2991 break;
2992
2993 case WINED3DSPR_CONST:
2994 {
2995 /* Relative addressing */
2996 if (reg->idx[0].rel_addr)
2997 {
2999 string_buffer_sprintf(register_name,
3000 "(%s + %u >= 0 && %s + %u < %u ? %s_c[%s + %u] : vec4(0.0))",
3001 rel_param0.param_str, reg->idx[0].offset,
3002 rel_param0.param_str, reg->idx[0].offset, shader->limits->constant_float,
3003 prefix, rel_param0.param_str, reg->idx[0].offset);
3004 else if (reg->idx[0].offset)
3005 string_buffer_sprintf(register_name, "%s_c[%s + %u]",
3006 prefix, rel_param0.param_str, reg->idx[0].offset);
3007 else
3008 string_buffer_sprintf(register_name, "%s_c[%s]", prefix, rel_param0.param_str);
3009 }
3010 else
3011 {
3012 if (shader_constant_is_local(shader, reg->idx[0].offset))
3013 string_buffer_sprintf(register_name, "%s_lc%u", prefix, reg->idx[0].offset);
3014 else
3015 string_buffer_sprintf(register_name, "%s_c[%u]", prefix, reg->idx[0].offset);
3016 }
3017 }
3018 break;
3019
3021 string_buffer_sprintf(register_name, "%s_i[%u]", prefix, reg->idx[0].offset);
3022 break;
3023
3025 string_buffer_sprintf(register_name, "%s_b[%u]", prefix, reg->idx[0].offset);
3026 break;
3027
3028 case WINED3DSPR_TEXTURE: /* case WINED3DSPR_ADDR: */
3030 string_buffer_sprintf(register_name, "T%u", reg->idx[0].offset);
3031 else
3032 string_buffer_sprintf(register_name, "A%u", reg->idx[0].offset);
3033 break;
3034
3035 case WINED3DSPR_LOOP:
3036 string_buffer_sprintf(register_name, "aL%u", ctx->state->current_loop_reg - 1);
3037 break;
3038
3039 case WINED3DSPR_SAMPLER:
3040 string_buffer_sprintf(register_name, "%s_sampler%u", prefix, reg->idx[0].offset);
3041 break;
3042
3044 if (reg->idx[0].offset >= gl_info->limits.buffers)
3045 WARN("Write to render target %u, only %d supported.\n",
3046 reg->idx[0].offset, gl_info->limits.buffers);
3047
3048 string_buffer_sprintf(register_name, "%s[%u]", get_fragment_output(gl_info), reg->idx[0].offset);
3049 break;
3050
3051 case WINED3DSPR_RASTOUT:
3052 string_buffer_sprintf(register_name, "%s", hwrastout_reg_names[reg->idx[0].offset]);
3053 break;
3054
3058 string_buffer_sprintf(register_name, "gl_FragDepth");
3059 break;
3060
3061 case WINED3DSPR_ATTROUT:
3062 if (!reg->idx[0].offset)
3063 string_buffer_sprintf(register_name, "%s_out[8]", prefix);
3064 else
3065 string_buffer_sprintf(register_name, "%s_out[9]", prefix);
3066 break;
3067
3069 /* Vertex shaders >= 3.0: WINED3DSPR_OUTPUT */
3070 if (reg->idx[0].rel_addr)
3071 string_buffer_sprintf(register_name, "%s_out[%s + %u]",
3072 prefix, rel_param0.param_str, reg->idx[0].offset);
3073 else
3074 string_buffer_sprintf(register_name, "%s_out[%u]", prefix, reg->idx[0].offset);
3075 break;
3076
3078 if (!reg->idx[0].offset)
3079 {
3080 /* vPos */
3081 string_buffer_sprintf(register_name, "vpos");
3082 }
3083 else if (reg->idx[0].offset == 1)
3084 {
3085 /* Note that gl_FrontFacing is a bool, while vFace is
3086 * a float for which the sign determines front/back */
3087 string_buffer_sprintf(register_name, "(gl_FrontFacing ? 1.0 : -1.0)");
3088 }
3089 else
3090 {
3091 FIXME("Unhandled misctype register %u.\n", reg->idx[0].offset);
3092 string_buffer_sprintf(register_name, "unrecognized_register");
3093 }
3094 break;
3095
3097 switch (reg->immconst_type)
3098 {
3100 switch (data_type)
3101 {
3102 case WINED3D_DATA_UNORM:
3103 case WINED3D_DATA_SNORM:
3104 case WINED3D_DATA_FLOAT:
3105 string_buffer_clear(register_name);
3106 shader_glsl_append_imm_vec(register_name, (const float *)reg->u.immconst_data, 1, gl_info);
3107 break;
3108 case WINED3D_DATA_INT:
3109 string_buffer_sprintf(register_name, "%#x", reg->u.immconst_data[0]);
3110 break;
3113 case WINED3D_DATA_UINT:
3114 string_buffer_sprintf(register_name, "%#xu", reg->u.immconst_data[0]);
3115 break;
3116 default:
3117 string_buffer_sprintf(register_name, "<unhandled data type %#x>", data_type);
3118 break;
3119 }
3120 break;
3121
3123 switch (data_type)
3124 {
3125 case WINED3D_DATA_UNORM:
3126 case WINED3D_DATA_SNORM:
3127 case WINED3D_DATA_FLOAT:
3128 string_buffer_clear(register_name);
3129 shader_glsl_append_imm_vec(register_name, (const float *)reg->u.immconst_data, 4, gl_info);
3130 break;
3131 case WINED3D_DATA_INT:
3132 string_buffer_sprintf(register_name, "ivec4(%#x, %#x, %#x, %#x)",
3133 reg->u.immconst_data[0], reg->u.immconst_data[1],
3134 reg->u.immconst_data[2], reg->u.immconst_data[3]);
3135 break;
3138 case WINED3D_DATA_UINT:
3139 string_buffer_sprintf(register_name, "uvec4(%#xu, %#xu, %#xu, %#xu)",
3140 reg->u.immconst_data[0], reg->u.immconst_data[1],
3141 reg->u.immconst_data[2], reg->u.immconst_data[3]);
3142 break;
3143 default:
3144 string_buffer_sprintf(register_name, "<unhandled data type %#x>", data_type);
3145 break;
3146 }
3147 break;
3148
3149 default:
3150 FIXME("Unhandled immconst type %#x\n", reg->immconst_type);
3151 string_buffer_sprintf(register_name, "<unhandled_immconst_type %#x>", reg->immconst_type);
3152 }
3153 break;
3154
3156 if (reg->idx[1].rel_addr)
3157 string_buffer_sprintf(register_name, "%s_cb%u[%s + %u]",
3158 prefix, reg->idx[0].offset, rel_param1.param_str, reg->idx[1].offset);
3159 else
3160 string_buffer_sprintf(register_name, "%s_cb%u[%u]", prefix, reg->idx[0].offset, reg->idx[1].offset);
3161 break;
3162
3164 if (reg->idx[0].rel_addr)
3165 string_buffer_sprintf(register_name, "%s_icb[%s + %u]",
3166 prefix, rel_param0.param_str, reg->idx[0].offset);
3167 else
3168 string_buffer_sprintf(register_name, "%s_icb[%u]", prefix, reg->idx[0].offset);
3169 break;
3170
3171 case WINED3DSPR_PRIMID:
3173 string_buffer_sprintf(register_name, "gl_PrimitiveIDIn");
3174 else
3175 string_buffer_sprintf(register_name, "gl_PrimitiveID");
3176 break;
3177
3178 case WINED3DSPR_IDXTEMP:
3179 if (reg->idx[1].rel_addr)
3180 string_buffer_sprintf(register_name, "X%u[%s + %u]",
3181 reg->idx[0].offset, rel_param1.param_str, reg->idx[1].offset);
3182 else
3183 string_buffer_sprintf(register_name, "X%u[%u]", reg->idx[0].offset, reg->idx[1].offset);
3184 break;
3185
3188 "int(gl_LocalInvocationIndex)", gl_info);
3189 break;
3190
3194 "gl_InvocationID", gl_info);
3195 break;
3196
3198 string_buffer_sprintf(register_name, "ivec3(gl_GlobalInvocationID)");
3199 break;
3200
3202 string_buffer_sprintf(register_name, "ivec3(gl_WorkGroupID)");
3203 break;
3204
3206 string_buffer_sprintf(register_name, "ivec3(gl_LocalInvocationID)");
3207 break;
3208
3212 "phase_instance_id", gl_info);
3213 break;
3214
3216 string_buffer_sprintf(register_name, "gl_TessCoord");
3217 break;
3218
3220 if (reg->idx[0].rel_addr)
3221 {
3222 if (reg->idx[1].rel_addr)
3223 string_buffer_sprintf(register_name, "shader_out[%s + %u].reg[%s + %u]",
3224 rel_param0.param_str, reg->idx[0].offset,
3225 rel_param1.param_str, reg->idx[1].offset);
3226 else
3227 string_buffer_sprintf(register_name, "shader_out[%s + %u].reg[%u]",
3228 rel_param0.param_str, reg->idx[0].offset,
3229 reg->idx[1].offset);
3230 }
3231 else if (reg->idx[1].rel_addr)
3232 {
3233 string_buffer_sprintf(register_name, "shader_out[%u].reg[%s + %u]",
3234 reg->idx[0].offset, rel_param1.param_str,
3235 reg->idx[1].offset);
3236 }
3237 else
3238 {
3239 string_buffer_sprintf(register_name, "shader_out[%u].reg[%u]",
3240 reg->idx[0].offset, reg->idx[1].offset);
3241 }
3242 break;
3243
3245 if (version->type == WINED3D_SHADER_TYPE_HULL)
3246 string_buffer_sprintf(register_name, "hs_out[%u]", reg->idx[0].offset);
3247 else
3248 string_buffer_sprintf(register_name, "vpc[%u]", reg->idx[0].offset);
3249 break;
3250
3252 string_buffer_sprintf(register_name, "gl_SampleMaskIn[0]");
3253 break;
3254
3256 string_buffer_sprintf(register_name, "sample_mask");
3257 break;
3258
3260 string_buffer_sprintf(register_name, "stencil_ref");
3261 break;
3262
3263 default:
3264 FIXME("Unhandled register type %#x.\n", reg->type);
3265 string_buffer_sprintf(register_name, "unrecognised_register");
3266 break;
3267 }
3268}
static void shader_glsl_fixup_scalar_register_variable(struct wined3d_string_buffer *register_name, const char *glsl_variable, const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:2845
static int reg
Definition: i386-dis.c:1290
@ WINED3DSPR_CONSTBOOL
@ WINED3DSPR_COLOROUT
@ WINED3DSPR_LOOP
@ WINED3DSPR_CONST
@ WINED3DSPR_OUTCONTROLPOINT
@ WINED3DSPR_INCONTROLPOINT
@ WINED3DSPR_TESSCOORD
@ WINED3DSPR_CONSTINT
@ WINED3DSPR_ATTROUT
@ WINED3DSPR_STENCILREF
@ WINED3DSPR_SAMPLER
@ WINED3DSPR_CONSTBUFFER
@ WINED3DSPR_IDXTEMP
@ WINED3DSPR_RASTOUT
@ WINED3DSPR_PATCHCONST
@ WINED3DSPR_INPUT
@ WINED3DSPR_SAMPLEMASK
@ WINED3DSPR_TEMP
@ WINED3DSPR_DEPTHOUT
@ WINED3DSPR_TEXCRDOUT
@ WINED3DSPR_COVERAGE
@ WINED3DSPR_TEXTURE
@ WINED3DSPR_MISCTYPE
@ WINED3DSPR_IMMCONSTBUFFER
@ WINED3D_IMMCONST_VEC4
static BOOL shader_constant_is_local(const struct wined3d_shader *shader, DWORD reg)

Referenced by shader_glsl_add_dst_param(), shader_glsl_add_src_param_ext(), shader_glsl_color_correction(), shader_glsl_loop(), shader_glsl_texreg2ar(), and shader_glsl_texreg2gb().

◆ shader_glsl_get_rel_op()

static const char * shader_glsl_get_rel_op ( enum wined3d_shader_rel_op  op)
static

Definition at line 3577 of file glsl_shader.c.

3578{
3579 switch (op)
3580 {
3581 case WINED3D_SHADER_REL_OP_GT: return ">";
3582 case WINED3D_SHADER_REL_OP_EQ: return "==";
3583 case WINED3D_SHADER_REL_OP_GE: return ">=";
3584 case WINED3D_SHADER_REL_OP_LT: return "<";
3585 case WINED3D_SHADER_REL_OP_NE: return "!=";
3586 case WINED3D_SHADER_REL_OP_LE: return "<=";
3587 default:
3588 FIXME("Unrecognized operator %#x.\n", op);
3589 return "(\?\?)";
3590 }
3591}
@ WINED3D_SHADER_REL_OP_GT
@ WINED3D_SHADER_REL_OP_LE
@ WINED3D_SHADER_REL_OP_GE
@ WINED3D_SHADER_REL_OP_EQ
@ WINED3D_SHADER_REL_OP_LT
@ WINED3D_SHADER_REL_OP_NE

Referenced by shader_glsl_breakc(), and shader_glsl_ifc().

◆ shader_glsl_get_resource_info()

static const struct wined3d_shader_resource_info * shader_glsl_get_resource_info ( const struct wined3d_shader_instruction *  ins,
const struct wined3d_shader_register *  reg 
)
static

Definition at line 5957 of file glsl_shader.c.

5959{
5960 const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps;
5961 unsigned int idx = reg->idx[0].offset;
5962
5963 if (reg->type == WINED3DSPR_RESOURCE)
5964 {
5965 if (idx >= ARRAY_SIZE(reg_maps->resource_info))
5966 {
5967 ERR("Invalid resource index %u.\n", idx);
5968 return NULL;
5969 }
5970 return &reg_maps->resource_info[idx];
5971 }
5972
5973 if (reg->type == WINED3DSPR_UAV)
5974 {
5975 if (idx >= ARRAY_SIZE(reg_maps->uav_resource_info))
5976 {
5977 ERR("Invalid UAV index %u.\n", idx);
5978 return NULL;
5979 }
5980 return &reg_maps->uav_resource_info[idx];
5981 }
5982
5983 FIXME("Unhandled register type %#x.\n", reg->type);
5984 return NULL;
5985}
@ WINED3DSPR_UAV

Referenced by shader_glsl_bufinfo(), shader_glsl_gather4(), and shader_glsl_sample_c().

◆ shader_glsl_get_sample_function()

static void shader_glsl_get_sample_function ( const struct wined3d_shader_context *  ctx,
DWORD  resource_idx,
DWORD  sampler_idx,
uint32_t  flags,
struct glsl_sample_function *  sample_function 
)
static

Definition at line 3610 of file glsl_shader.c.

3612{
3613 enum wined3d_shader_resource_type resource_type;
3614 struct shader_glsl_ctx_priv *priv = ctx->backend_data;
3615 const struct wined3d_gl_info *gl_info = priv->gl_info;
3616 BOOL shadow = shader_sampler_is_shadow(ctx->shader, priv->cur_ps_args, resource_idx, sampler_idx);
3621 const char *base = "texture", *type_part = "", *suffix = "";
3622 unsigned int coord_size, deriv_size;
3623
3624 resource_type = ctx->reg_maps->shader_version.type == WINED3D_SHADER_TYPE_PIXEL
3625 ? pixelshader_get_resource_type(ctx->reg_maps, resource_idx, priv->cur_ps_args->tex_types)
3626 : ctx->reg_maps->resource_info[resource_idx].type;
3627
3628 sample_function->data_type = ctx->reg_maps->resource_info[resource_idx].data_type;
3629
3630 if (resource_type >= ARRAY_SIZE(resource_type_info))
3631 {
3632 ERR("Unexpected resource type %#x.\n", resource_type);
3633 resource_type = WINED3D_SHADER_RESOURCE_TEXTURE_2D;
3634 }
3635
3636 /* Note that there's no such thing as a projected cube texture. */
3637 if (resource_type == WINED3D_SHADER_RESOURCE_TEXTURE_CUBE)
3638 projected = FALSE;
3639
3640 if (needs_legacy_glsl_syntax(gl_info))
3641 {
3642 if (shadow)
3643 base = "shadow";
3644
3645 type_part = resource_type_info[resource_type].type_part;
3646 if (!type_part[0] && resource_type != WINED3D_SHADER_RESOURCE_TEXTURE_CUBEARRAY)
3647 FIXME("Unhandled resource type %#x.\n", resource_type);
3648
3649 if (!lod && grad && !shader_glsl_has_core_grad(gl_info))
3650 {
3651 if (gl_info->supported[ARB_SHADER_TEXTURE_LOD])
3652 suffix = "ARB";
3653 else
3654 FIXME("Unsupported grad function.\n");
3655 }
3656 }
3657
3659 {
3660 static const uint32_t texel_fetch_flags = WINED3D_GLSL_SAMPLE_LOAD | WINED3D_GLSL_SAMPLE_OFFSET;
3661 if (flags & ~texel_fetch_flags)
3662 ERR("Unexpected flags %#x for texelFetch.\n", flags & ~texel_fetch_flags);
3663
3664 base = "texelFetch";
3665 type_part = "";
3666 }
3667
3668 sample_function->name = string_buffer_get(priv->string_buffers);
3669 string_buffer_sprintf(sample_function->name, "%s%s%s%s%s%s", base, type_part, projected ? "Proj" : "",
3670 lod ? "Lod" : grad ? "Grad" : "", offset ? "Offset" : "", suffix);
3671
3672 shader_glsl_get_coord_size(resource_type, &coord_size, &deriv_size);
3673 if (shadow)
3674 ++coord_size;
3675 sample_function->offset_size = offset ? deriv_size : 0;
3676 sample_function->coord_mask = wined3d_mask_from_size(coord_size);
3677 sample_function->deriv_mask = wined3d_mask_from_size(deriv_size);
3678 sample_function->output_single_component = shadow && !needs_legacy_glsl_syntax(gl_info);
3679}
GLint lod
Definition: glext.h:7795
#define WINED3D_GLSL_SAMPLE_LOAD
Definition: glsl_shader.c:45
#define WINED3D_GLSL_SAMPLE_LOD
Definition: glsl_shader.c:43
#define WINED3D_GLSL_SAMPLE_PROJECTED
Definition: glsl_shader.c:42
static BOOL shader_glsl_has_core_grad(const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:3593
#define WINED3D_GLSL_SAMPLE_GRAD
Definition: glsl_shader.c:44
#define WINED3D_GLSL_SAMPLE_OFFSET
Definition: glsl_shader.c:46
const char * type_part
Definition: glsl_shader.c:52
unsigned int coord_mask
Definition: glsl_shader.c:97
struct wined3d_string_buffer * name
Definition: glsl_shader.c:96

Referenced by shader_glsl_ld(), shader_glsl_sample(), shader_glsl_sample_c(), shader_glsl_tex(), shader_glsl_texbem(), shader_glsl_texdp3tex(), shader_glsl_texldd(), shader_glsl_texldl(), shader_glsl_texm3x2tex(), shader_glsl_texm3x3spec(), shader_glsl_texm3x3tex(), shader_glsl_texm3x3vspec(), shader_glsl_texreg2ar(), shader_glsl_texreg2gb(), and shader_glsl_texreg2rgb().

◆ shader_glsl_get_shader_model()

static unsigned int shader_glsl_get_shader_model ( const struct wined3d_gl_info *  gl_info)
static

Definition at line 11339 of file glsl_shader.c.

11340{
11341 BOOL shader_model_4 = gl_info->glsl_version >= MAKEDWORD_VERSION(1, 50)
11343 && gl_info->supported[ARB_TEXTURE_SWIZZLE]
11344 && gl_info->supported[EXT_SHADER_INTEGER_MIX];
11345
11346 if (shader_model_4
11347 && gl_info->supported[ARB_COMPUTE_SHADER]
11348 && gl_info->supported[ARB_CULL_DISTANCE]
11350 && gl_info->supported[ARB_GPU_SHADER5]
11353 && gl_info->supported[ARB_SHADER_IMAGE_SIZE]
11356 && gl_info->supported[ARB_TEXTURE_GATHER]
11358 return 5;
11359
11360 if (shader_model_4)
11361 return 4;
11362
11363 /* Support for texldd and texldl instructions in pixel shaders is required
11364 * for SM3. */
11366 return 3;
11367
11368 return 2;
11369}
@ ARB_COMPUTE_SHADER
Definition: wined3d_gl.h:60
@ ARB_TESSELLATION_SHADER
Definition: wined3d_gl.h:123
@ ARB_TRANSFORM_FEEDBACK3
Definition: wined3d_gl.h:150
@ ARB_TEXTURE_SWIZZLE
Definition: wined3d_gl.h:146

Referenced by shader_glsl_get_caps().

◆ shader_glsl_get_swizzle()

static void shader_glsl_get_swizzle ( const struct wined3d_shader_src_param *  param,
BOOL  fixup,
DWORD  mask,
char *  swizzle_str 
)
static

Definition at line 3334 of file glsl_shader.c.

3336{
3337 if (shader_is_scalar(&param->reg))
3338 *swizzle_str = '\0';
3339 else
3340 shader_glsl_swizzle_to_str(param->swizzle, fixup, mask, swizzle_str);
3341}

Referenced by shader_glsl_add_src_param_ext(), shader_glsl_bufinfo(), shader_glsl_interpolate(), shader_glsl_ld_uav(), shader_glsl_resinfo(), shader_glsl_sample_info(), and shader_glsl_texcoord().

◆ shader_glsl_get_version()

static unsigned int shader_glsl_get_version ( const struct wined3d_gl_info *  gl_info)
static

Definition at line 398 of file glsl_shader.c.

399{
400 if (gl_info->glsl_version >= MAKEDWORD_VERSION(4, 40))
401 return 440;
402 else if (gl_info->glsl_version >= MAKEDWORD_VERSION(1, 50))
403 return 150;
404 else if (gl_info->glsl_version >= MAKEDWORD_VERSION(1, 30))
405 return 130;
406 else
407 return 120;
408}

Referenced by shader_glsl_add_version_declaration(), shader_glsl_has_core_grad(), shader_glsl_mov(), shader_glsl_use_interface_blocks(), and shader_glsl_use_layout_qualifier().

◆ shader_glsl_get_write_mask()

static DWORD shader_glsl_get_write_mask ( const struct wined3d_shader_dst_param *  param,
char *  write_mask 
)
static

◆ shader_glsl_get_write_mask_size()

◆ shader_glsl_handle_instruction()

static void shader_glsl_handle_instruction ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 11669 of file glsl_shader.c.

11669 {
11670 SHADER_HANDLER hw_fct;
11671
11672 /* Select handler */
11674
11675 /* Unhandled opcode */
11676 if (!hw_fct)
11677 {
11678 FIXME("Backend can't handle opcode %s.\n", debug_d3dshaderinstructionhandler(ins->handler_idx));
11679 return;
11680 }
11681 hw_fct(ins);
11682
11684}
static void shader_glsl_add_instruction_modifiers(const struct wined3d_shader_instruction *ins)
Definition: glsl_shader.c:3534
static const SHADER_HANDLER shader_glsl_instruction_handler_table[WINED3DSIH_TABLE_SIZE]
void(* SHADER_HANDLER)(const struct wined3d_shader_instruction *)

◆ shader_glsl_has_core_grad()

static BOOL shader_glsl_has_core_grad ( const struct wined3d_gl_info *  gl_info)
static

Definition at line 3593 of file glsl_shader.c.

3594{
3595 return shader_glsl_get_version(gl_info) >= 130 || gl_info->supported[EXT_GPU_SHADER4];
3596}

Referenced by shader_glsl_get_sample_function(), shader_glsl_get_shader_model(), shader_glsl_texldd(), and shader_glsl_texldl().

◆ shader_glsl_if()

static void shader_glsl_if ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5209 of file glsl_shader.c.

5210{
5212 shader_addline(ins->ctx->buffer, "{\n");
5213}

◆ shader_glsl_ifc()

static void shader_glsl_ifc ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5215 of file glsl_shader.c.

5216{
5217 struct glsl_src_param src0_param;
5218 struct glsl_src_param src1_param;
5219
5220 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
5221 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0, &src1_param);
5222
5223 shader_addline(ins->ctx->buffer, "if (%s %s %s) {\n",
5224 src0_param.param_str, shader_glsl_get_rel_op(ins->flags), src1_param.param_str);
5225}

◆ shader_glsl_init_context_state()

static void shader_glsl_init_context_state ( struct wined3d_context *  context)
static

Definition at line 11330 of file glsl_shader.c.

11331{
11332 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
11333 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
11334
11335 gl_info->gl_ops.gl.p_glEnable(GL_PROGRAM_POINT_SIZE);
11336 checkGLcall("GL_PROGRAM_POINT_SIZE");
11337}
#define GL_PROGRAM_POINT_SIZE
Definition: glext.h:816

◆ shader_glsl_init_ds_uniform_locations()

static void shader_glsl_init_ds_uniform_locations ( const struct wined3d_gl_info *  gl_info,
struct shader_glsl_priv *  priv,
GLuint  program_id,
struct glsl_ds_program *  ds 
)
static

Definition at line 10210 of file glsl_shader.c.

10212{
10213 ds->pos_fixup_location = GL_EXTCALL(glGetUniformLocation(program_id, "pos_fixup"));
10214}

Referenced by set_glsl_shader_program().

◆ shader_glsl_init_gs_uniform_locations()

static void shader_glsl_init_gs_uniform_locations ( const struct wined3d_gl_info *  gl_info,
struct shader_glsl_priv *  priv,
GLuint  program_id,
struct glsl_gs_program *  gs 
)
static

Definition at line 10216 of file glsl_shader.c.

10218{
10219 gs->pos_fixup_location = GL_EXTCALL(glGetUniformLocation(program_id, "pos_fixup"));
10220}

Referenced by set_glsl_shader_program().

◆ shader_glsl_init_ps_uniform_locations()

static void shader_glsl_init_ps_uniform_locations ( const struct wined3d_gl_info *  gl_info,
struct shader_glsl_priv *  priv,
GLuint  program_id,
struct glsl_ps_program *  ps,
unsigned int  ps_c_count 
)
static

Definition at line 10222 of file glsl_shader.c.

10224{
10225 unsigned int i;
10227
10228 for (i = 0; i < ps_c_count; ++i)
10229 {
10230 string_buffer_sprintf(name, "ps_c[%u]", i);
10231 ps->uniform_f_locations[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10232 }
10233 memset(&ps->uniform_f_locations[ps_c_count], 0xff, (WINED3D_MAX_PS_CONSTS_F - ps_c_count) * sizeof(GLuint));
10234
10235 for (i = 0; i < WINED3D_MAX_CONSTS_I; ++i)
10236 {
10237 string_buffer_sprintf(name, "ps_i[%u]", i);
10238 ps->uniform_i_locations[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10239 }
10240
10241 for (i = 0; i < WINED3D_MAX_CONSTS_B; ++i)
10242 {
10243 string_buffer_sprintf(name, "ps_b[%u]", i);
10244 ps->uniform_b_locations[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10245 }
10246
10247 for (i = 0; i < WINED3D_MAX_FFP_TEXTURES; ++i)
10248 {
10249 string_buffer_sprintf(name, "bumpenv_mat%u", i);
10250 ps->bumpenv_mat_location[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10251 string_buffer_sprintf(name, "bumpenv_lum_scale%u", i);
10252 ps->bumpenv_lum_scale_location[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10253 string_buffer_sprintf(name, "bumpenv_lum_offset%u", i);
10254 ps->bumpenv_lum_offset_location[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10255 string_buffer_sprintf(name, "tss_const%u", i);
10256 ps->tss_constant_location[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10257 }
10258
10259 ps->tex_factor_location = GL_EXTCALL(glGetUniformLocation(program_id, "tex_factor"));
10260 ps->specular_enable_location = GL_EXTCALL(glGetUniformLocation(program_id, "specular_enable"));
10261
10262 ps->fog_color_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_fog.color"));
10263 ps->fog_density_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_fog.density"));
10264 ps->fog_end_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_fog.end"));
10265 ps->fog_scale_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_fog.scale"));
10266
10267 ps->alpha_test_ref_location = GL_EXTCALL(glGetUniformLocation(program_id, "alpha_test_ref"));
10268
10269 ps->color_key_location = GL_EXTCALL(glGetUniformLocation(program_id, "color_key"));
10270
10272}
GLint color_key_location
Definition: glsl_shader.c:230
GLint tss_constant_location[WINED3D_MAX_FFP_TEXTURES]
Definition: glsl_shader.c:222
GLint fog_density_location
Definition: glsl_shader.c:226
GLint tex_factor_location
Definition: glsl_shader.c:223
GLint alpha_test_ref_location
Definition: glsl_shader.c:229
GLint uniform_b_locations[WINED3D_MAX_CONSTS_B]
Definition: glsl_shader.c:218
GLint bumpenv_lum_scale_location[WINED3D_MAX_FFP_TEXTURES]
Definition: glsl_shader.c:220
GLint fog_color_location
Definition: glsl_shader.c:225
GLint uniform_i_locations[WINED3D_MAX_CONSTS_I]
Definition: glsl_shader.c:217
GLint fog_end_location
Definition: glsl_shader.c:227
GLint bumpenv_lum_offset_location[WINED3D_MAX_FFP_TEXTURES]
Definition: glsl_shader.c:221
GLint uniform_f_locations[WINED3D_MAX_PS_CONSTS_F]
Definition: glsl_shader.c:216
GLint bumpenv_mat_location[WINED3D_MAX_FFP_TEXTURES]
Definition: glsl_shader.c:219
GLint specular_enable_location
Definition: glsl_shader.c:224
GLint fog_scale_location
Definition: glsl_shader.c:228
#define WINED3D_MAX_CONSTS_B
Definition: wined3d.h:1602
#define WINED3D_MAX_CONSTS_I
Definition: wined3d.h:1603

Referenced by set_glsl_shader_program().

◆ shader_glsl_init_transform_feedback()

static void shader_glsl_init_transform_feedback ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
GLuint  program_id,
struct wined3d_shader *  shader 
)
static

Definition at line 1136 of file glsl_shader.c.

1138{
1139 const struct wined3d_stream_output_desc *so_desc = shader->u.gs.so_desc;
1140 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1142 unsigned int i, count, length;
1143 const char **varyings;
1144 char *strings;
1145 GLenum mode;
1146
1147 if (!so_desc)
1148 return;
1149
1150 if (gl_info->supported[ARB_TRANSFORM_FEEDBACK3])
1151 {
1153 }
1154 else
1155 {
1157
1158 for (i = 0; i < so_desc->element_count; ++i)
1159 {
1160 if (!so_desc->elements[i].semantic_name)
1161 {
1162 FIXME("ARB_transform_feedback3 is needed for stream output gaps.\n");
1163 return;
1164 }
1165 ++element_count[so_desc->elements[i].output_slot];
1166 }
1167
1168 if (element_count[0] == so_desc->element_count)
1169 {
1171 }
1172 else
1173 {
1175 for (i = 0; i < ARRAY_SIZE(element_count); ++i)
1176 {
1177 if (element_count[i] != 1)
1178 break;
1179 }
1180 for (; i < ARRAY_SIZE(element_count); ++i)
1181 {
1182 if (element_count[i])
1183 {
1184 FIXME("Only single element per buffer is allowed in separate mode.\n");
1185 return;
1186 }
1187 }
1188 }
1189 }
1190
1192
1194 {
1195 FIXME("No varyings to record, disabling transform feedback.\n");
1196 shader->u.gs.so_desc = NULL;
1198 return;
1199 }
1200
1201 if (!(varyings = calloc(count, sizeof(*varyings))))
1202 {
1203 ERR("Out of memory.\n");
1205 return;
1206 }
1207 if (!(strings = calloc(length, sizeof(*strings))))
1208 {
1209 ERR("Out of memory.\n");
1210 free(varyings);
1212 return;
1213 }
1214
1216 GL_EXTCALL(glTransformFeedbackVaryings(program_id, count, varyings, mode));
1217 checkGLcall("glTransformFeedbackVaryings");
1218
1219 free(varyings);
1220 free(strings);
1222}
#define GL_SEPARATE_ATTRIBS
Definition: glext.h:556
static BOOL shader_glsl_generate_transform_feedback_varyings(struct wined3d_string_buffer *buffer, const char **varyings, unsigned int *varying_count, char *strings, unsigned int *strings_length, GLenum buffer_mode, struct wined3d_shader *shader)
Definition: glsl_shader.c:1046

Referenced by set_glsl_shader_program().

◆ shader_glsl_init_uniform_block_bindings()

static void shader_glsl_init_uniform_block_bindings ( const struct wined3d_gl_info *  gl_info,
struct shader_glsl_priv *  priv,
GLuint  program_id,
const struct wined3d_shader_reg_maps *  reg_maps 
)
static

Definition at line 843 of file glsl_shader.c.

846{
847 const char *prefix = shader_glsl_get_prefix(reg_maps->shader_version.type);
849 unsigned int i, base, count;
850 GLuint block_idx;
851
853 return;
854
857 for (i = 0; i < count; ++i)
858 {
859 if (!reg_maps->cb_sizes[i])
860 continue;
861
862 string_buffer_sprintf(name, "block_%s_cb%u", prefix, i);
863 block_idx = GL_EXTCALL(glGetUniformBlockIndex(program_id, name->buffer));
864 GL_EXTCALL(glUniformBlockBinding(program_id, block_idx, base + i));
865 }
866 checkGLcall("glUniformBlockBinding");
868}

Referenced by shader_glsl_load_program_resources().

◆ shader_glsl_init_vs_uniform_locations()

static void shader_glsl_init_vs_uniform_locations ( const struct wined3d_gl_info *  gl_info,
struct shader_glsl_priv *  priv,
GLuint  program_id,
struct glsl_vs_program *  vs,
unsigned int  vs_c_count 
)
static

Definition at line 10126 of file glsl_shader.c.

10128{
10129 unsigned int i;
10131
10132 for (i = 0; i < vs_c_count; ++i)
10133 {
10134 string_buffer_sprintf(name, "vs_c[%u]", i);
10135 vs->uniform_f_locations[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10136 }
10137 memset(&vs->uniform_f_locations[vs_c_count], 0xff, (WINED3D_MAX_VS_CONSTS_F - vs_c_count) * sizeof(GLuint));
10138
10139 for (i = 0; i < WINED3D_MAX_CONSTS_I; ++i)
10140 {
10141 string_buffer_sprintf(name, "vs_i[%u]", i);
10142 vs->uniform_i_locations[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10143 }
10144
10145 for (i = 0; i < WINED3D_MAX_CONSTS_B; ++i)
10146 {
10147 string_buffer_sprintf(name, "vs_b[%u]", i);
10148 vs->uniform_b_locations[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10149 }
10150
10151 vs->pos_fixup_location = GL_EXTCALL(glGetUniformLocation(program_id, "pos_fixup"));
10152 vs->base_vertex_id_location = GL_EXTCALL(glGetUniformLocation(program_id, "base_vertex_id"));
10153
10154 for (i = 0; i < MAX_VERTEX_BLENDS; ++i)
10155 {
10156 string_buffer_sprintf(name, "ffp_modelview_matrix[%u]", i);
10157 vs->modelview_matrix_location[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10158 }
10159 vs->projection_matrix_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_projection_matrix"));
10160 vs->normal_matrix_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_normal_matrix"));
10161 for (i = 0; i < WINED3D_MAX_FFP_TEXTURES; ++i)
10162 {
10163 string_buffer_sprintf(name, "ffp_texture_matrix[%u]", i);
10164 vs->texture_matrix_location[i] = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10165 }
10166 vs->material_ambient_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_material.ambient"));
10167 vs->material_diffuse_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_material.diffuse"));
10168 vs->material_specular_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_material.specular"));
10169 vs->material_emissive_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_material.emissive"));
10170 vs->material_shininess_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_material.shininess"));
10171 vs->light_ambient_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_light_ambient"));
10172 for (i = 0; i < WINED3D_MAX_ACTIVE_LIGHTS; ++i)
10173 {
10174 string_buffer_sprintf(name, "ffp_light[%u].diffuse", i);
10175 vs->light_location[i].diffuse = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10176 string_buffer_sprintf(name, "ffp_light[%u].specular", i);
10177 vs->light_location[i].specular = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10178 string_buffer_sprintf(name, "ffp_light[%u].ambient", i);
10179 vs->light_location[i].ambient = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10180 string_buffer_sprintf(name, "ffp_light[%u].position", i);
10181 vs->light_location[i].position = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10182 string_buffer_sprintf(name, "ffp_light[%u].direction", i);
10183 vs->light_location[i].direction = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10184 string_buffer_sprintf(name, "ffp_light[%u].range", i);
10185 vs->light_location[i].range = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10186 string_buffer_sprintf(name, "ffp_light[%u].falloff", i);
10187 vs->light_location[i].falloff = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10188 string_buffer_sprintf(name, "ffp_light[%u].c_att", i);
10189 vs->light_location[i].c_att = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10190 string_buffer_sprintf(name, "ffp_light[%u].l_att", i);
10191 vs->light_location[i].l_att = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10192 string_buffer_sprintf(name, "ffp_light[%u].q_att", i);
10193 vs->light_location[i].q_att = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10194 string_buffer_sprintf(name, "ffp_light[%u].cos_htheta", i);
10195 vs->light_location[i].cos_htheta = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10196 string_buffer_sprintf(name, "ffp_light[%u].cos_hphi", i);
10197 vs->light_location[i].cos_hphi = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
10198 }
10199 vs->pointsize_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_point.size"));
10200 vs->pointsize_min_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_point.size_min"));
10201 vs->pointsize_max_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_point.size_max"));
10202 vs->pointsize_c_att_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_point.c_att"));
10203 vs->pointsize_l_att_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_point.l_att"));
10204 vs->pointsize_q_att_location = GL_EXTCALL(glGetUniformLocation(program_id, "ffp_point.q_att"));
10205 vs->clip_planes_location = GL_EXTCALL(glGetUniformLocation(program_id, "clip_planes"));
10206
10208}

Referenced by set_glsl_shader_program().

◆ shader_glsl_input_pack()

static void shader_glsl_input_pack ( const struct wined3d_shader *  shader,
struct wined3d_string_buffer *  buffer,
const struct wined3d_shader_signature *  input_signature,
const struct wined3d_shader_reg_maps *  reg_maps,
const struct ps_compile_args *  args,
const struct wined3d_gl_info *  gl_info,
BOOL  unroll 
)
static

Definition at line 6936 of file glsl_shader.c.

6940{
6941 unsigned int i;
6942
6943 for (i = 0; i < input_signature->element_count; ++i)
6944 {
6945 const struct wined3d_shader_signature_element *input = &input_signature->elements[i];
6946 const char *semantic_name;
6948 char reg_mask[6];
6949
6950 /* Unused */
6951 if (!(reg_maps->input_registers & (1u << input->register_idx)))
6952 continue;
6953
6954 semantic_name = input->semantic_name;
6955 semantic_idx = input->semantic_idx;
6956 shader_glsl_write_mask_to_str(input->mask, reg_mask);
6957
6958 if (args->vp_mode == WINED3D_VP_MODE_SHADER)
6959 {
6960 if (input->sysval_semantic == WINED3D_SV_POSITION && !semantic_idx)
6961 {
6962 shader_addline(buffer, "ps_in[%u]%s = vpos%s;\n",
6963 shader->u.ps.input_reg_map[input->register_idx], reg_mask, reg_mask);
6964 }
6966 {
6967 shader_addline(buffer, "ps_in[%u] = vec4(gl_PointCoord.xy, 0.0, 0.0);\n", input->register_idx);
6968 }
6969 else if (input->sysval_semantic == WINED3D_SV_IS_FRONT_FACE)
6970 {
6971 shader_addline(buffer, "ps_in[%u]%s = uintBitsToFloat(gl_FrontFacing ? 0xffffffffu : 0u);\n",
6972 input->register_idx, reg_mask);
6973 }
6974 else if (input->sysval_semantic == WINED3D_SV_SAMPLE_INDEX)
6975 {
6976 if (gl_info->supported[ARB_SAMPLE_SHADING])
6977 shader_addline(buffer, "ps_in[%u]%s = intBitsToFloat(gl_SampleID);\n",
6978 input->register_idx, reg_mask);
6979 else
6980 FIXME("ARB_sample_shading is not supported.\n");
6981 }
6982 else if (input->sysval_semantic == WINED3D_SV_RENDER_TARGET_ARRAY_INDEX && !semantic_idx)
6983 {
6985 shader_addline(buffer, "ps_in[%u]%s = intBitsToFloat(gl_Layer);\n",
6986 input->register_idx, reg_mask);
6987 else
6988 FIXME("ARB_fragment_layer_viewport is not supported.\n");
6989 }
6990 else if (input->sysval_semantic == WINED3D_SV_VIEWPORT_ARRAY_INDEX && !semantic_idx)
6991 {
6992 if (gl_info->supported[ARB_VIEWPORT_ARRAY])
6993 shader_addline(buffer, "ps_in[%u]%s = intBitsToFloat(gl_ViewportIndex);\n",
6994 input->register_idx, reg_mask);
6995 else
6996 FIXME("ARB_viewport_array is not supported.\n");
6997 }
6998 else
6999 {
7000 if (input->sysval_semantic)
7001 FIXME("Unhandled sysval semantic %#x.\n", input->sysval_semantic);
7002 shader_addline(buffer, unroll ? "ps_in[%u]%s = %s%u%s;\n" : "ps_in[%u]%s = %s[%u]%s;\n",
7003 shader->u.ps.input_reg_map[input->register_idx], reg_mask,
7005 shader->u.ps.input_reg_map[input->register_idx], reg_mask);
7006 }
7007 }
7009 {
7010 if (args->pointsprite)
7011 shader_addline(buffer, "ps_in[%u] = vec4(gl_PointCoord.xy, 0.0, 0.0);\n",
7012 shader->u.ps.input_reg_map[input->register_idx]);
7013 else if (args->vp_mode == WINED3D_VP_MODE_NONE && args->texcoords_initialized & (1u << semantic_idx))
7014 shader_addline(buffer, "ps_in[%u]%s = %s[%u]%s;\n",
7015 shader->u.ps.input_reg_map[input->register_idx], reg_mask,
7017 ? "gl_TexCoord" : "ffp_varying_texcoord", semantic_idx, reg_mask);
7018 else
7019 shader_addline(buffer, "ps_in[%u]%s = vec4(0.0, 0.0, 0.0, 0.0)%s;\n",
7020 shader->u.ps.input_reg_map[input->register_idx], reg_mask, reg_mask);
7021 }
7023 {
7024 if (!semantic_idx)
7025 shader_addline(buffer, "ps_in[%u]%s = vec4(ffp_varying_diffuse)%s;\n",
7026 shader->u.ps.input_reg_map[input->register_idx], reg_mask, reg_mask);
7027 else if (semantic_idx == 1)
7028 shader_addline(buffer, "ps_in[%u]%s = vec4(ffp_varying_specular)%s;\n",
7029 shader->u.ps.input_reg_map[input->register_idx], reg_mask, reg_mask);
7030 else
7031 shader_addline(buffer, "ps_in[%u]%s = vec4(0.0, 0.0, 0.0, 0.0)%s;\n",
7032 shader->u.ps.input_reg_map[input->register_idx], reg_mask, reg_mask);
7033 }
7034 else
7035 {
7036 shader_addline(buffer, "ps_in[%u]%s = vec4(0.0, 0.0, 0.0, 0.0)%s;\n",
7037 shader->u.ps.input_reg_map[input->register_idx], reg_mask, reg_mask);
7038 }
7039 }
7040}
static const char * shader_glsl_shader_input_name(const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:2148
@ WINED3D_VP_MODE_NONE
@ WINED3D_SV_VIEWPORT_ARRAY_INDEX
@ WINED3D_SV_SAMPLE_INDEX
@ WINED3D_SV_IS_FRONT_FACE
@ WINED3D_SV_RENDER_TARGET_ARRAY_INDEX

Referenced by shader_glsl_generate_fragment_shader().

◆ shader_glsl_interpolate()

static void shader_glsl_interpolate ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 6188 of file glsl_shader.c.

6189{
6190 const struct wined3d_shader_src_param *input = &ins->src[0];
6191 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
6192 struct glsl_src_param sample_param;
6193 char dst_swizzle[6];
6194 DWORD write_mask;
6195
6196 write_mask = shader_glsl_append_dst(buffer, ins);
6197 shader_glsl_get_swizzle(input, FALSE, write_mask, dst_swizzle);
6198
6199 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0, &sample_param);
6200 shader_addline(buffer, "interpolateAtSample(shader_in.reg%u, %s)%s);\n",
6201 input->reg.idx[0].offset, sample_param.param_str, dst_swizzle);
6202}

◆ shader_glsl_interpolation_qualifiers()

static const char * shader_glsl_interpolation_qualifiers ( enum wined3d_shader_interpolation_mode  mode)
static

Definition at line 2158 of file glsl_shader.c.

2159{
2160 switch (mode)
2161 {
2163 return "flat ";
2165 return "noperspective ";
2166 default:
2167 FIXME("Unhandled interpolation mode %#x.\n", mode);
2168 case WINED3DSIM_NONE:
2169 case WINED3DSIM_LINEAR:
2170 return "";
2171 }
2172}
@ WINED3DSIM_LINEAR
@ WINED3DSIM_NONE
@ WINED3DSIM_LINEAR_NOPERSPECTIVE
@ WINED3DSIM_CONSTANT

Referenced by shader_glsl_declare_shader_inputs(), and shader_glsl_declare_shader_outputs().

◆ shader_glsl_invalidate_contexts_program()

static void shader_glsl_invalidate_contexts_program ( struct wined3d_device *  device,
const struct glsl_shader_prog_link *  program 
)
static

Definition at line 10975 of file glsl_shader.c.

10977{
10978 const struct glsl_context_data *ctx_data;
10979 struct wined3d_context *context;
10980 unsigned int i;
10981
10982 for (i = 0; i < device->context_count; ++i)
10983 {
10984 context = device->contexts[i];
10985 ctx_data = context->shader_backend_data;
10986
10987 if (ctx_data->glsl_program == program)
10989 }
10990}

Referenced by shader_glsl_destroy().

◆ shader_glsl_invalidate_current_program()

static void shader_glsl_invalidate_current_program ( struct wined3d_context *  context)
static

Definition at line 10939 of file glsl_shader.c.

10940{
10941 struct glsl_context_data *ctx_data = context->shader_backend_data;
10942
10943 ctx_data->glsl_program = NULL;
10944 context->shader_update_mask = (1u << WINED3D_SHADER_TYPE_PIXEL)
10947 | (1u << WINED3D_SHADER_TYPE_HULL)
10950}

Referenced by shader_glsl_disable(), and shader_glsl_invalidate_contexts_program().

◆ shader_glsl_label()

static void shader_glsl_label ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5302 of file glsl_shader.c.

5303{
5304 shader_addline(ins->ctx->buffer, "}\n");
5305 shader_addline(ins->ctx->buffer, "void subroutine%u()\n{\n", ins->src[0].reg.idx[0].offset);
5306
5307 /* Subroutines appear at the end of the shader. */
5308 ins->ctx->state->in_subroutine = TRUE;
5309}

◆ shader_glsl_ld()

static void shader_glsl_ld ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 6204 of file glsl_shader.c.

6205{
6206 const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps;
6207 struct glsl_src_param coord_param, lod_param, sample_param;
6208 unsigned int resource_idx, sampler_idx, sampler_bind_idx;
6209 struct glsl_sample_function sample_function;
6211 BOOL has_lod_param;
6212
6215
6216 resource_idx = ins->src[1].reg.idx[0].offset;
6217 sampler_idx = WINED3D_SAMPLER_DEFAULT;
6218
6219 if (resource_idx >= ARRAY_SIZE(reg_maps->resource_info))
6220 {
6221 ERR("Invalid resource index %u.\n", resource_idx);
6222 return;
6223 }
6224 has_lod_param = is_mipmapped(reg_maps->resource_info[resource_idx].type);
6225
6226 shader_glsl_get_sample_function(ins->ctx, resource_idx, sampler_idx, flags, &sample_function);
6227 shader_glsl_add_src_param(ins, &ins->src[0], sample_function.coord_mask, &coord_param);
6228 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &lod_param);
6229 sampler_bind_idx = shader_glsl_find_sampler(&reg_maps->sampler_map, resource_idx, sampler_idx);
6230 if (is_multisampled(reg_maps->resource_info[resource_idx].type))
6231 {
6232 shader_glsl_add_src_param(ins, &ins->src[2], WINED3DSP_WRITEMASK_0, &sample_param);
6233 shader_glsl_gen_sample_code(ins, sampler_bind_idx, &sample_function, ins->src[1].swizzle,
6234 NULL, NULL, NULL, &ins->texel_offset, "%s, %s", coord_param.param_str, sample_param.param_str);
6235 }
6236 else
6237 {
6238 shader_glsl_gen_sample_code(ins, sampler_bind_idx, &sample_function, ins->src[1].swizzle,
6239 NULL, NULL, has_lod_param ? lod_param.param_str : NULL, &ins->texel_offset,
6240 "%s", coord_param.param_str);
6241 }
6242 shader_glsl_release_sample_function(ins->ctx, &sample_function);
6243}
static void shader_glsl_get_sample_function(const struct wined3d_shader_context *ctx, DWORD resource_idx, DWORD sampler_idx, uint32_t flags, struct glsl_sample_function *sample_function)
Definition: glsl_shader.c:3610
static BOOL is_mipmapped(enum wined3d_shader_resource_type resource_type)
Definition: glsl_shader.c:6027
static void shader_glsl_release_sample_function(const struct wined3d_shader_context *ctx, struct glsl_sample_function *sample_function)
Definition: glsl_shader.c:3681

◆ shader_glsl_ld_raw_structured()

static void shader_glsl_ld_raw_structured ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5751 of file glsl_shader.c.

5752{
5753 const char *prefix = shader_glsl_get_prefix(ins->ctx->reg_maps->shader_version.type);
5754 const struct wined3d_shader_src_param *src = &ins->src[ins->src_count - 1];
5755 unsigned int i, swizzle, resource_idx, bind_idx, stride, src_idx = 0;
5756 const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps;
5757 struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
5758 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
5759 struct glsl_src_param structure_idx, offset;
5762 const char *function, *resource;
5763
5764 resource_idx = src->reg.idx[0].offset;
5765 if (src->reg.type == WINED3DSPR_RESOURCE)
5766 {
5767 if (resource_idx >= ARRAY_SIZE(reg_maps->resource_info))
5768 {
5769 ERR("Invalid resource index %u.\n", resource_idx);
5770 return;
5771 }
5772 stride = reg_maps->resource_info[resource_idx].stride;
5773 bind_idx = shader_glsl_find_sampler(&reg_maps->sampler_map, resource_idx, WINED3D_SAMPLER_DEFAULT);
5774 function = "texelFetch";
5775 resource = "sampler";
5776 }
5777 else if (src->reg.type == WINED3DSPR_UAV)
5778 {
5779 if (resource_idx >= ARRAY_SIZE(reg_maps->uav_resource_info))
5780 {
5781 ERR("Invalid UAV index %u.\n", resource_idx);
5782 return;
5783 }
5784 stride = reg_maps->uav_resource_info[resource_idx].stride;
5785 bind_idx = resource_idx;
5786 function = "imageLoad";
5787 resource = "image";
5788 }
5789 else
5790 {
5791 if (resource_idx >= reg_maps->tgsm_count)
5792 {
5793 ERR("Invalid TGSM index %u.\n", resource_idx);
5794 return;
5795 }
5796 stride = reg_maps->tgsm[resource_idx].stride;
5797 bind_idx = resource_idx;
5798 function = NULL;
5799 resource = "g";
5800 }
5801
5804 {
5805 shader_glsl_add_src_param(ins, &ins->src[src_idx++], WINED3DSP_WRITEMASK_0, &structure_idx);
5806 shader_addline(address, "%s * %u + ", structure_idx.param_str, stride);
5807 }
5809 shader_addline(address, "%s / 4", offset.param_str);
5810
5811 dst = ins->dst[0];
5812 if (shader_glsl_get_write_mask_size(dst.write_mask) > 1)
5813 {
5814 /* The instruction is split into multiple lines. The first lines may
5815 * overwrite source parameters of the following lines. */
5816 shader_addline(buffer, "tmp0.x = intBitsToFloat(%s);\n", address->buffer);
5817 string_buffer_sprintf(address, "floatBitsToInt(tmp0.x)");
5818 }
5819
5820 for (i = 0; i < 4; ++i)
5821 {
5822 dst.write_mask = ins->dst[0].write_mask & (WINED3DSP_WRITEMASK_0 << i);
5823 if (!shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &dst, 0, dst.reg.data_type))
5824 continue;
5825
5827 if (function)
5828 shader_addline(buffer, "%s(%s_%s%u, %s + %u).x);\n",
5829 function, prefix, resource, bind_idx, address->buffer, swizzle);
5830 else
5831 shader_addline(buffer, "%s_%s%u[%s + %u]);\n",
5832 prefix, resource, bind_idx, address->buffer, swizzle);
5833 }
5834
5836}
@ WINED3DSIH_LD_STRUCTURED

◆ shader_glsl_ld_uav()

static void shader_glsl_ld_uav ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5717 of file glsl_shader.c.

5718{
5719 const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps;
5720 const struct wined3d_shader_version *version = &reg_maps->shader_version;
5721 enum wined3d_shader_resource_type resource_type;
5722 struct glsl_src_param image_coord_param;
5724 DWORD coord_mask, write_mask;
5725 unsigned int uav_idx;
5726 char dst_swizzle[6];
5727
5728 uav_idx = ins->src[1].reg.idx[0].offset;
5729 if (uav_idx >= ARRAY_SIZE(reg_maps->uav_resource_info))
5730 {
5731 ERR("Invalid UAV index %u.\n", uav_idx);
5732 return;
5733 }
5734 resource_type = reg_maps->uav_resource_info[uav_idx].type;
5735 if (resource_type >= ARRAY_SIZE(resource_type_info))
5736 {
5737 ERR("Unexpected resource type %#x.\n", resource_type);
5738 resource_type = WINED3D_SHADER_RESOURCE_TEXTURE_2D;
5739 }
5740 data_type = reg_maps->uav_resource_info[uav_idx].data_type;
5741 coord_mask = wined3d_mask_from_size(resource_type_info[resource_type].coord_size);
5742
5743 write_mask = shader_glsl_append_dst_ext(ins->ctx->buffer, ins, &ins->dst[0], 0, data_type);
5744 shader_glsl_get_swizzle(&ins->src[1], FALSE, write_mask, dst_swizzle);
5745
5746 shader_glsl_add_src_param(ins, &ins->src[0], coord_mask, &image_coord_param);
5747 shader_addline(ins->ctx->buffer, "imageLoad(%s_image%u, %s)%s);\n",
5748 shader_glsl_get_prefix(version->type), uav_idx, image_coord_param.param_str, dst_swizzle);
5749}

◆ shader_glsl_lit()

static void shader_glsl_lit ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_LIT instruction in GLSL: dst.x = dst.w = 1.0 dst.y = (src0.x > 0) ? src0.x dst.z = (src0.x > 0) ? ((src0.y > 0) ? pow(src0.y, src.w) : 0) : 0 where src.w is clamped at +- 128

Definition at line 4870 of file glsl_shader.c.

4871{
4872 struct glsl_src_param src0_param;
4873 struct glsl_src_param src1_param;
4874 struct glsl_src_param src3_param;
4875 char dst_mask[6];
4876
4877 shader_glsl_append_dst(ins->ctx->buffer, ins);
4878 shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
4879
4880 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
4881 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_1, &src1_param);
4882 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &src3_param);
4883
4884 /* The sdk specifies the instruction like this
4885 * dst.x = 1.0;
4886 * if(src.x > 0.0) dst.y = src.x
4887 * else dst.y = 0.0.
4888 * if(src.x > 0.0 && src.y > 0.0) dst.z = pow(src.y, power);
4889 * else dst.z = 0.0;
4890 * dst.w = 1.0;
4891 * (where power = src.w clamped between -128 and 128)
4892 *
4893 * Obviously that has quite a few conditionals in it which we don't like. So the first step is this:
4894 * dst.x = 1.0 ... No further explanation needed
4895 * dst.y = max(src.y, 0.0); ... If x < 0.0, use 0.0, otherwise x. Same as the conditional
4896 * dst.z = x > 0.0 ? pow(max(y, 0.0), p) : 0; ... 0 ^ power is 0, and otherwise we use y anyway
4897 * dst.w = 1.0. ... Nothing fancy.
4898 *
4899 * So we still have one conditional in there. So do this:
4900 * dst.z = pow(max(0.0, src.y) * step(0.0, src.x), power);
4901 *
4902 * step(0.0, x) will return 1 if src.x > 0.0, and 0 otherwise. So if y is 0 we get pow(0.0 * 1.0, power),
4903 * which sets dst.z to 0. If y > 0, but x = 0.0, we get pow(y * 0.0, power), which results in 0 too.
4904 * if both x and y are > 0, we get pow(y * 1.0, power), as it is supposed to.
4905 *
4906 * Unfortunately pow(0.0 ^ 0.0) returns NaN on most GPUs, but lit with src.y = 0 and src.w = 0 returns
4907 * a non-NaN value in dst.z. What we return doesn't matter, as long as it is not NaN. Return 0, which is
4908 * what all Windows HW drivers and GL_ARB_vertex_program's LIT do.
4909 */
4910 shader_addline(ins->ctx->buffer,
4911 "vec4(1.0, max(%s, 0.0), %s == 0.0 ? 0.0 : "
4912 "pow(max(0.0, %s) * step(0.0, %s), clamp(%s, -128.0, 128.0)), 1.0)%s);\n",
4913 src0_param.param_str, src3_param.param_str, src1_param.param_str,
4914 src0_param.param_str, src3_param.param_str, dst_mask);
4915}

◆ shader_glsl_load_constants()

static void shader_glsl_load_constants ( struct shader_glsl_priv *  priv,
struct wined3d_context *  context,
const struct wined3d_state *  state 
)
static

Definition at line 1716 of file glsl_shader.c.

1718{
1719 const struct wined3d_shader *vshader = state->shader[WINED3D_SHADER_TYPE_VERTEX];
1720 const struct wined3d_shader *pshader = state->shader[WINED3D_SHADER_TYPE_PIXEL];
1721 const struct glsl_context_data *ctx_data = context->shader_backend_data;
1722 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
1723 struct glsl_shader_prog_link *prog = ctx_data->glsl_program;
1724 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1725 float position_fixup[4 * WINED3D_MAX_VIEWPORTS];
1726 struct wined3d_device *device = context->device;
1727 unsigned int constant_version;
1728 DWORD update_mask;
1729 int i;
1730
1731 /* No GLSL program set - nothing to do. */
1732 if (!prog)
1733 return;
1734
1735 constant_version = prog->constant_version;
1736 update_mask = context->constant_update_mask & prog->constant_update_mask;
1737
1738 if (vshader && vshader->is_ffp_vs)
1739 {
1740 /* The shader's constant update mask is WINED3D_SHADER_CONST_VS_F.
1741 * This may be set from shader_glsl_update_graphics_program().
1742 * However, we also need to update constants when FFP flags change. */
1743 static const uint32_t vs_update_mask = WINED3D_SHADER_CONST_VS_F
1751
1752 if (context->constant_update_mask & vs_update_mask)
1753 shader_glsl_load_constants_f(vshader, context_gl, device->push_constants[WINED3D_PUSH_CONSTANTS_VS_FFP],
1754 prog->vs.uniform_f_locations, &priv->vconst_heap, priv->stack, constant_version);
1755 }
1756 else
1757 {
1758 if (update_mask & WINED3D_SHADER_CONST_VS_F)
1759 shader_glsl_load_constants_f(vshader, context_gl, device->push_constants[WINED3D_PUSH_CONSTANTS_VS_F],
1760 prog->vs.uniform_f_locations, &priv->vconst_heap, priv->stack, constant_version);
1761
1762 if (update_mask & WINED3D_SHADER_CONST_VS_I)
1763 shader_glsl_load_constants_i(vshader, context_gl, device->push_constants[WINED3D_PUSH_CONSTANTS_VS_I],
1764 prog->vs.uniform_i_locations, vshader->reg_maps.integer_constants);
1765
1766 if (update_mask & WINED3D_SHADER_CONST_VS_B)
1767 shader_glsl_load_constants_b(vshader, context_gl, device->push_constants[WINED3D_PUSH_CONSTANTS_VS_B],
1768 prog->vs.uniform_b_locations, vshader->reg_maps.boolean_constants);
1769 }
1770
1771 if (update_mask & WINED3D_SHADER_CONST_VS_CLIP_PLANES)
1772 {
1773 if (gl_info->supported[WINED3D_GLSL_130])
1774 {
1775 for (i = 0; i < gl_info->limits.user_clip_distances; ++i)
1777 }
1778 else
1779 {
1781 }
1782 }
1783
1784 if (update_mask & WINED3D_SHADER_CONST_VS_POINTSIZE)
1786
1787 if (update_mask & WINED3D_SHADER_CONST_POS_FIXUP)
1788 {
1789 unsigned int fixup_count = state->shader[WINED3D_SHADER_TYPE_GEOMETRY] ?
1790 max(state->viewport_count, 1) : 1;
1791 shader_get_position_fixup(context, state, fixup_count, position_fixup);
1793 GL_EXTCALL(glUniform4fv(prog->gs.pos_fixup_location, fixup_count, position_fixup));
1794 else if (state->shader[WINED3D_SHADER_TYPE_DOMAIN])
1795 GL_EXTCALL(glUniform4fv(prog->ds.pos_fixup_location, 1, position_fixup));
1796 else
1797 GL_EXTCALL(glUniform4fv(prog->vs.pos_fixup_location, 1, position_fixup));
1798 checkGLcall("glUniform4fv");
1799 }
1800
1801 if (update_mask & WINED3D_SHADER_CONST_BASE_VERTEX_ID)
1802 {
1803 GL_EXTCALL(glUniform1i(prog->vs.base_vertex_id_location, state->base_vertex_index));
1804 checkGLcall("base vertex id");
1805 }
1806
1807 if (update_mask & WINED3D_SHADER_CONST_FFP_MODELVIEW)
1808 {
1809 const struct wined3d_ffp_vs_constants *constants;
1810
1812
1813 GL_EXTCALL(glUniformMatrix4fv(prog->vs.modelview_matrix_location[0], 1,
1814 FALSE, &constants->modelview.modelview_matrices[0]._11));
1815 checkGLcall("glUniformMatrix4fv");
1816
1818 }
1819
1820 if (update_mask & WINED3D_SHADER_CONST_FFP_VERTEXBLEND)
1821 {
1822 const struct wined3d_ffp_vs_constants *constants;
1823
1825
1826 for (i = 1; i < MAX_VERTEX_BLENDS; ++i)
1827 {
1828 if (prog->vs.modelview_matrix_location[i] == -1)
1829 break;
1830
1831 GL_EXTCALL(glUniformMatrix4fv(prog->vs.modelview_matrix_location[i],
1832 1, FALSE, &constants->modelview.modelview_matrices[i]._11));
1833 checkGLcall("glUniformMatrix4fv");
1834 }
1835 }
1836
1837 if (update_mask & WINED3D_SHADER_CONST_FFP_PROJ)
1838 {
1839 const struct wined3d_ffp_vs_constants *constants;
1840 struct wined3d_matrix projection;
1841
1843
1845 GL_EXTCALL(glUniformMatrix4fv(prog->vs.projection_matrix_location, 1, FALSE, &projection._11));
1846 checkGLcall("glUniformMatrix4fv");
1847 }
1848
1849 if (update_mask & WINED3D_SHADER_CONST_FFP_TEXMATRIX)
1850 {
1851 const struct wined3d_ffp_vs_constants *constants;
1852
1854
1855 for (i = 0; i < WINED3D_MAX_FFP_TEXTURES; ++i)
1857 }
1858
1859 if (update_mask & WINED3D_SHADER_CONST_FFP_MATERIAL)
1861
1862 if (update_mask & WINED3D_SHADER_CONST_FFP_LIGHTS)
1863 {
1864 const struct wined3d_ffp_vs_constants *constants;
1865 DWORD point_count = 0;
1866 DWORD spot_count = 0;
1867 DWORD directional_count = 0;
1868 DWORD parallel_point_count = 0;
1869
1871
1872 for (i = 0; i < WINED3D_MAX_ACTIVE_LIGHTS; ++i)
1873 {
1874 if (!state->light_state.lights[i])
1875 continue;
1876
1877 switch (state->light_state.lights[i]->OriginalParms.type)
1878 {
1880 ++point_count;
1881 break;
1882 case WINED3D_LIGHT_SPOT:
1883 ++spot_count;
1884 break;
1886 ++directional_count;
1887 break;
1889 ++parallel_point_count;
1890 break;
1891 default:
1892 FIXME("Unhandled light type %#x.\n", state->light_state.lights[i]->OriginalParms.type);
1893 break;
1894 }
1895 }
1896
1897 GL_EXTCALL(glUniform3fv(prog->vs.light_ambient_location, 1, &constants->light.ambient.r));
1898 checkGLcall("glUniform3fv");
1899
1900 for (i = 0; i < point_count; ++i)
1902 WINED3D_LIGHT_POINT, &constants->light.lights[i], prog);
1903 for (; i < point_count + spot_count; ++i)
1905 WINED3D_LIGHT_SPOT, &constants->light.lights[i], prog);
1906 for (; i < point_count + spot_count + directional_count; ++i)
1908 WINED3D_LIGHT_DIRECTIONAL, &constants->light.lights[i], prog);
1909 for (; i < point_count + spot_count + directional_count + parallel_point_count; ++i)
1911 WINED3D_LIGHT_PARALLELPOINT, &constants->light.lights[i], prog);
1912 }
1913
1914 if (pshader && pshader->is_ffp_ps)
1915 {
1916 static const uint32_t ps_update_mask = WINED3D_SHADER_CONST_PS_F
1920
1921 if (context->constant_update_mask & ps_update_mask)
1922 shader_glsl_load_constants_f(pshader, context_gl, device->push_constants[WINED3D_PUSH_CONSTANTS_PS_FFP],
1923 prog->ps.uniform_f_locations, &priv->pconst_heap, priv->stack, constant_version);
1924 }
1925 else
1926 {
1927 if (update_mask & WINED3D_SHADER_CONST_PS_F)
1928 shader_glsl_load_constants_f(pshader, context_gl, device->push_constants[WINED3D_PUSH_CONSTANTS_PS_F],
1929 prog->ps.uniform_f_locations, &priv->pconst_heap, priv->stack, constant_version);
1930
1931 if (update_mask & WINED3D_SHADER_CONST_PS_I)
1932 shader_glsl_load_constants_i(pshader, context_gl, device->push_constants[WINED3D_PUSH_CONSTANTS_PS_I],
1933 prog->ps.uniform_i_locations, pshader->reg_maps.integer_constants);
1934
1935 if (update_mask & WINED3D_SHADER_CONST_PS_B)
1936 shader_glsl_load_constants_b(pshader, context_gl, device->push_constants[WINED3D_PUSH_CONSTANTS_PS_B],
1937 prog->ps.uniform_b_locations, pshader->reg_maps.boolean_constants);
1938 }
1939
1940 if (update_mask & WINED3D_SHADER_CONST_PS_BUMP_ENV)
1941 {
1943 context_gl->c.device->push_constants[WINED3D_PUSH_CONSTANTS_PS_FFP], &context_gl->c);
1944
1945 for (i = 0; i < WINED3D_MAX_FFP_TEXTURES; ++i)
1946 {
1947 if (prog->ps.bumpenv_mat_location[i] == -1)
1948 continue;
1949
1950 GL_EXTCALL(glUniformMatrix2fv(prog->ps.bumpenv_mat_location[i], 1, 0,
1951 &constants->bumpenv.matrices[i]._00));
1952
1953 if (prog->ps.bumpenv_lum_scale_location[i] != -1)
1954 {
1955 GL_EXTCALL(glUniform1fv(prog->ps.bumpenv_lum_scale_location[i], 1,
1956 &constants->bumpenv.lscale[i]));
1957 GL_EXTCALL(glUniform1fv(prog->ps.bumpenv_lum_offset_location[i], 1,
1958 &constants->bumpenv.loffset[i]));
1959 }
1960 }
1961
1962 checkGLcall("bump env uniforms");
1963 }
1964
1965 if (update_mask & WINED3D_SHADER_CONST_FFP_COLOR_KEY)
1966 {
1968 context_gl->c.device->push_constants[WINED3D_PUSH_CONSTANTS_PS_FFP], &context_gl->c);
1969
1970 GL_EXTCALL(glUniform4fv(prog->ps.color_key_location, 2, &constants->color_key[0].r));
1971 }
1972
1973 if (update_mask & WINED3D_SHADER_CONST_FFP_PS)
1974 {
1975 const struct wined3d_ffp_ps_constants *constants;
1976
1978 context_gl->c.device->push_constants[WINED3D_PUSH_CONSTANTS_PS_FFP], &context_gl->c);
1979
1980 if (prog->ps.tex_factor_location != -1)
1981 GL_EXTCALL(glUniform4fv(prog->ps.tex_factor_location, 1, &constants->texture_factor.r));
1982
1983 GL_EXTCALL(glUniform4fv(prog->ps.specular_enable_location, 1, &constants->specular_enable.r));
1984
1985 for (i = 0; i < WINED3D_MAX_FFP_TEXTURES; ++i)
1986 {
1987 if (prog->ps.tss_constant_location[i] == -1)
1988 continue;
1989
1990 GL_EXTCALL(glUniform4fv(prog->ps.tss_constant_location[i], 1, &constants->texture_constants[i].r));
1991 }
1992
1993 checkGLcall("fixed function uniforms");
1994 }
1995
1996 if (update_mask & WINED3D_SHADER_CONST_PS_FOG)
1998
1999 if (update_mask & WINED3D_SHADER_CONST_PS_ALPHA_TEST)
2000 {
2002 context_gl->c.device->push_constants[WINED3D_PUSH_CONSTANTS_PS_FFP], &context_gl->c);
2003
2004 GL_EXTCALL(glUniform1f(prog->ps.alpha_test_ref_location, constants->alpha_test_ref));
2005 checkGLcall("alpha test emulation uniform");
2006 }
2007
2008 if (priv->next_constant_version == UINT_MAX)
2009 {
2010 TRACE("Max constant version reached, resetting to 0.\n");
2012 priv->next_constant_version = 1;
2013 }
2014 else
2015 {
2016 prog->constant_version = priv->next_constant_version++;
2017 }
2018}
#define UINT_MAX
Definition: limits.h:27
void ffp_vertex_update_clip_plane_constants(const struct wined3d_gl_info *gl_info, const struct wined3d_state *state)
Definition: ffp_gl.c:1007
static void shader_glsl_load_constants_f(const struct wined3d_shader *shader, struct wined3d_context_gl *context_gl, struct wined3d_buffer *constant_buffer, const GLint *constant_locations, const struct constant_heap *heap, unsigned char *stack, unsigned int version)
Definition: glsl_shader.c:1374
static void shader_glsl_ffp_vertex_normalmatrix_uniform(const struct wined3d_context_gl *context_gl, const struct wined3d_ffp_vs_constants *constants, struct glsl_shader_prog_link *prog)
Definition: glsl_shader.c:1565
static void shader_glsl_ffp_vertex_texmatrix_uniform(const struct wined3d_context_gl *context_gl, const struct wined3d_ffp_vs_constants *constants, unsigned int tex, struct glsl_shader_prog_link *prog)
Definition: glsl_shader.c:1578
static void shader_glsl_load_fog_uniform(const struct wined3d_context_gl *context_gl, const struct wined3d_state *state, struct glsl_shader_prog_link *prog)
Definition: glsl_shader.c:1685
static void get_projection_matrix(const struct wined3d_context *context, const struct wined3d_ffp_vs_constants *constants, const struct wined3d_state *state, struct wined3d_matrix *mat)
Definition: glsl_shader.c:1480
static void shader_glsl_load_constants_i(const struct wined3d_shader *shader, struct wined3d_context_gl *context_gl, struct wined3d_buffer *constant_buffer, const GLint locations[WINED3D_MAX_CONSTS_I], uint32_t constants_set)
Definition: glsl_shader.c:1408
static void shader_glsl_pointsize_uniform(struct wined3d_context_gl *context_gl, const struct wined3d_state *state, struct glsl_shader_prog_link *prog)
Definition: glsl_shader.c:1658
static void shader_glsl_ffp_vertex_material_uniform(struct wined3d_context_gl *context_gl, const struct wined3d_state *state, struct glsl_shader_prog_link *prog)
Definition: glsl_shader.c:1593
static void reset_program_constant_version(struct wine_rb_entry *entry, void *context)
Definition: glsl_shader.c:1475
static void shader_glsl_ffp_vertex_light_uniform(const struct wined3d_context_gl *context_gl, const struct wined3d_state *state, unsigned int light, enum wined3d_light_type type, const struct wined3d_light_constants *constants, struct glsl_shader_prog_link *prog)
Definition: glsl_shader.c:1610
static void shader_glsl_clip_plane_uniform(const struct wined3d_context_gl *context_gl, const struct wined3d_state *state, unsigned int index, struct glsl_shader_prog_link *prog)
Definition: glsl_shader.c:1708
static void shader_glsl_load_constants_b(const struct wined3d_shader *shader, struct wined3d_context_gl *context_gl, struct wined3d_buffer *constant_buffer, const GLint locations[WINED3D_MAX_CONSTS_B], uint32_t constants_set)
Definition: glsl_shader.c:1443
#define wine_rb_for_each_entry
Definition: rbtree.h:407
@ WINED3D_GLSL_130
Definition: wined3d_gl.h:237
@ WINED3D_PUSH_CONSTANTS_PS_B
@ WINED3D_PUSH_CONSTANTS_VS_B
@ WINED3D_PUSH_CONSTANTS_VS_I
@ WINED3D_PUSH_CONSTANTS_PS_F
@ WINED3D_PUSH_CONSTANTS_PS_I
@ WINED3D_PUSH_CONSTANTS_VS_F
static void shader_get_position_fixup(const struct wined3d_context *context, const struct wined3d_state *state, unsigned int fixup_count, float *position_fixup)

Referenced by shader_glsl_apply_draw_state().

◆ shader_glsl_load_constants_b()

static void shader_glsl_load_constants_b ( const struct wined3d_shader *  shader,
struct wined3d_context_gl *  context_gl,
struct wined3d_buffer *  constant_buffer,
const GLint  locations[WINED3D_MAX_CONSTS_B],
uint32_t  constants_set 
)
static

Definition at line 1443 of file glsl_shader.c.

1445{
1446 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1447 unsigned int i;
1448 struct list* ptr;
1449
1450 if (constant_buffer)
1451 {
1452 const BOOL *constants = wined3d_buffer_load_sysmem(constant_buffer, &context_gl->c);
1453
1454 while (constants_set)
1455 {
1456 i = wined3d_bit_scan(&constants_set);
1457 GL_EXTCALL(glUniform1iv(locations[i], 1, &constants[i]));
1458 }
1459 }
1460
1461 /* Load immediate constants */
1462 ptr = list_head(&shader->constantsB);
1463 while (ptr)
1464 {
1465 const struct wined3d_shader_lconst *lconst = LIST_ENTRY(ptr, const struct wined3d_shader_lconst, entry);
1466 unsigned int idx = lconst->idx;
1467 const GLint *values = (const GLint *)lconst->value;
1468
1469 GL_EXTCALL(glUniform1iv(locations[idx], 1, values));
1470 ptr = list_next(&shader->constantsB, ptr);
1471 }
1472 checkGLcall("glUniform1iv()");
1473}
GLsizei const GLint * locations
Definition: glext.h:10542
__WINE_SERVER_LIST_INLINE struct list * list_next(const struct list *list, const struct list *elem)
Definition: list.h:117
Definition: list.h:15
#define LIST_ENTRY(type)
Definition: queue.h:175

Referenced by shader_glsl_load_constants().

◆ shader_glsl_load_constants_f()

static void shader_glsl_load_constants_f ( const struct wined3d_shader *  shader,
struct wined3d_context_gl *  context_gl,
struct wined3d_buffer *  constant_buffer,
const GLint *  constant_locations,
const struct constant_heap *  heap,
unsigned char *  stack,
unsigned int  version 
)
static

Definition at line 1374 of file glsl_shader.c.

1377{
1378 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1379 const struct wined3d_shader_lconst *lconst;
1380
1381 if (constant_buffer)
1382 {
1383 const struct wined3d_vec4 *constants = wined3d_buffer_load_sysmem(constant_buffer, &context_gl->c);
1384
1385 /* 1.X pshaders have the constants clamped to [-1;1] implicitly. */
1386 if (shader->reg_maps.shader_version.major == 1
1387 && shader->reg_maps.shader_version.type == WINED3D_SHADER_TYPE_PIXEL)
1388 walk_constant_heap_clamped(gl_info, constants, constant_locations, heap, stack, version);
1389 else
1390 walk_constant_heap(gl_info, constants, constant_locations, heap, stack, version);
1391 }
1392
1393 if (!shader->load_local_constsF)
1394 {
1395 TRACE("No need to load local float constants for this shader.\n");
1396 return;
1397 }
1398
1399 /* Immediate constants are clamped to [-1;1] at shader creation time if needed */
1400 LIST_FOR_EACH_ENTRY(lconst, &shader->constantsF, struct wined3d_shader_lconst, entry)
1401 {
1402 GL_EXTCALL(glUniform4fv(constant_locations[lconst->idx], 1, (const GLfloat *)lconst->value));
1403 }
1404 checkGLcall("glUniform4fv()");
1405}
static void walk_constant_heap_clamped(const struct wined3d_gl_info *gl_info, const struct wined3d_vec4 *constants, const GLint *constant_locations, const struct constant_heap *heap, unsigned char *stack, DWORD version)
Definition: glsl_shader.c:1315
static void walk_constant_heap(const struct wined3d_gl_info *gl_info, const struct wined3d_vec4 *constants, const GLint *constant_locations, const struct constant_heap *heap, unsigned char *stack, DWORD version)
Definition: glsl_shader.c:1225
Definition: format.c:80

Referenced by shader_glsl_load_constants().

◆ shader_glsl_load_constants_i()

static void shader_glsl_load_constants_i ( const struct wined3d_shader *  shader,
struct wined3d_context_gl *  context_gl,
struct wined3d_buffer *  constant_buffer,
const GLint  locations[WINED3D_MAX_CONSTS_I],
uint32_t  constants_set 
)
static

Definition at line 1408 of file glsl_shader.c.

1410{
1411 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1412 unsigned int i;
1413 struct list* ptr;
1414
1415 if (constant_buffer)
1416 {
1417 const struct wined3d_ivec4 *constants = wined3d_buffer_load_sysmem(constant_buffer, &context_gl->c);
1418
1419 while (constants_set)
1420 {
1421 /* We found this uniform name in the program - go ahead and send the data */
1422 i = wined3d_bit_scan(&constants_set);
1423 GL_EXTCALL(glUniform4iv(locations[i], 1, &constants[i].x));
1424 }
1425 }
1426
1427 /* Load immediate constants */
1428 ptr = list_head(&shader->constantsI);
1429 while (ptr)
1430 {
1431 const struct wined3d_shader_lconst *lconst = LIST_ENTRY(ptr, const struct wined3d_shader_lconst, entry);
1432 unsigned int idx = lconst->idx;
1433 const GLint *values = (const GLint *)lconst->value;
1434
1435 /* We found this uniform name in the program - go ahead and send the data */
1436 GL_EXTCALL(glUniform4iv(locations[idx], 1, values));
1437 ptr = list_next(&shader->constantsI, ptr);
1438 }
1439 checkGLcall("glUniform4iv()");
1440}

Referenced by shader_glsl_load_constants().

◆ shader_glsl_load_fog_uniform()

static void shader_glsl_load_fog_uniform ( const struct wined3d_context_gl *  context_gl,
const struct wined3d_state *  state,
struct glsl_shader_prog_link *  prog 
)
static

Definition at line 1685 of file glsl_shader.c.

1687{
1688 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1689 struct wined3d_color color;
1690 float start, end, scale;
1691 union
1692 {
1693 DWORD d;
1694 float f;
1695 } tmpvalue;
1696
1698 GL_EXTCALL(glUniform4fv(prog->ps.fog_color_location, 1, &color.r));
1699 tmpvalue.d = state->render_states[WINED3D_RS_FOGDENSITY];
1700 GL_EXTCALL(glUniform1f(prog->ps.fog_density_location, tmpvalue.f));
1701 get_fog_start_end(&context_gl->c, state, &start, &end);
1702 scale = 1.0f / (end - start);
1703 GL_EXTCALL(glUniform1f(prog->ps.fog_end_location, end));
1704 GL_EXTCALL(glUniform1f(prog->ps.fog_scale_location, scale));
1705 checkGLcall("fog emulation uniforms");
1706}
static void wined3d_color_from_d3dcolor(struct wined3d_color *wined3d_colour, D3DCOLOR d3d_colour)
Definition: device.c:34
void get_fog_start_end(const struct wined3d_context *context, const struct wined3d_state *state, float *start, float *end)
Definition: utils.c:5703
GLuint start
Definition: gl.h:1545
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:9032
#define f
Definition: ke_i.h:83
@ WINED3D_RS_FOGCOLOR
Definition: wined3d.h:317
@ WINED3D_RS_FOGDENSITY
Definition: wined3d.h:321

Referenced by shader_glsl_load_constants().

◆ shader_glsl_load_icb()

static void shader_glsl_load_icb ( const struct wined3d_gl_info *  gl_info,
struct shader_glsl_priv *  priv,
GLuint  program_id,
const struct wined3d_shader_reg_maps *  reg_maps 
)
static

Definition at line 946 of file glsl_shader.c.

948{
949 const struct wined3d_shader_immediate_constant_buffer *icb = reg_maps->icb;
950
951 if (icb)
952 {
953 struct wined3d_string_buffer *icb_name = string_buffer_get(&priv->string_buffers);
954 const char *prefix = shader_glsl_get_prefix(reg_maps->shader_version.type);
955 GLint icb_location;
956
957 string_buffer_sprintf(icb_name, "%s_icb", prefix);
958 icb_location = GL_EXTCALL(glGetUniformLocation(program_id, icb_name->buffer));
959 GL_EXTCALL(glUniform4fv(icb_location, icb->vec4_count, (const GLfloat *)icb->data));
960 checkGLcall("Load immediate constant buffer");
961
962 string_buffer_release(&priv->string_buffers, icb_name);
963 }
964}
uint32_t data[MAX_IMMEDIATE_CONSTANT_BUFFER_SIZE]

Referenced by shader_glsl_load_program_resources().

◆ shader_glsl_load_images()

static void shader_glsl_load_images ( const struct wined3d_gl_info *  gl_info,
struct shader_glsl_priv *  priv,
GLuint  program_id,
const struct wined3d_shader_reg_maps *  reg_maps 
)
static

Definition at line 967 of file glsl_shader.c.

969{
970 const char *prefix = shader_glsl_get_prefix(reg_maps->shader_version.type);
973 unsigned int i;
974
976 return;
977
979 for (i = 0; i < MAX_UNORDERED_ACCESS_VIEWS; ++i)
980 {
981 if (!reg_maps->uav_resource_info[i].type)
982 continue;
983
984 string_buffer_sprintf(name, "%s_image%u", prefix, i);
985 location = GL_EXTCALL(glGetUniformLocation(program_id, name->buffer));
986 if (location == -1)
987 continue;
988
989 TRACE("Loading image %s on unit %u.\n", name->buffer, i);
990 GL_EXTCALL(glUniform1i(location, i));
991 }
992 checkGLcall("Load image bindings");
994}
#define MAX_UNORDERED_ACCESS_VIEWS

Referenced by set_glsl_shader_program(), and shader_glsl_compile_compute_shader().

◆ shader_glsl_load_program_resources()

static void shader_glsl_load_program_resources ( const struct wined3d_context_gl *  context_gl,
struct shader_glsl_priv *  priv,
GLuint  program_id,
const struct wined3d_shader *  shader 
)
static

Definition at line 997 of file glsl_shader.c.

999{
1000 const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
1001
1002 shader_glsl_init_uniform_block_bindings(context_gl->gl_info, priv, program_id, reg_maps);
1003 shader_glsl_load_icb(context_gl->gl_info, priv, program_id, reg_maps);
1004 /* Texture unit mapping is set up to be the same each time the shader
1005 * program is used so we can hardcode the sampler uniform values. */
1006 shader_glsl_load_samplers(&context_gl->c, priv, program_id, reg_maps);
1007}
static void shader_glsl_init_uniform_block_bindings(const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, const struct wined3d_shader_reg_maps *reg_maps)
Definition: glsl_shader.c:843
static void shader_glsl_load_icb(const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, const struct wined3d_shader_reg_maps *reg_maps)
Definition: glsl_shader.c:946

Referenced by set_glsl_shader_program(), and shader_glsl_compile_compute_shader().

◆ shader_glsl_load_samplers()

static void shader_glsl_load_samplers ( const struct wined3d_context *  context,
struct shader_glsl_priv *  priv,
GLuint  program_id,
const struct wined3d_shader_reg_maps *  reg_maps 
)
static

Definition at line 927 of file glsl_shader.c.

929{
930 const struct wined3d_context_gl *context_gl = wined3d_context_gl_const(context);
931 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
932 const struct wined3d_shader_version *shader_version;
933 const unsigned int *tex_unit_map;
934 unsigned int base, count;
935 const char *prefix;
936
938 return;
939
940 shader_version = reg_maps ? &reg_maps->shader_version : NULL;
941 prefix = shader_glsl_get_prefix(shader_version ? shader_version->type : WINED3D_SHADER_TYPE_PIXEL);
942 tex_unit_map = wined3d_context_gl_get_tex_unit_mapping(context_gl, shader_version, &base, &count);
943 shader_glsl_load_samplers_range(gl_info, priv, program_id, prefix, base, count, tex_unit_map);
944}
static void shader_glsl_load_samplers_range(const struct wined3d_gl_info *gl_info, struct shader_glsl_priv *priv, GLuint program_id, const char *prefix, unsigned int base, unsigned int count, const unsigned int *tex_unit_map)
Definition: glsl_shader.c:871
enum wined3d_shader_type type
static const struct wined3d_context_gl * wined3d_context_gl_const(const struct wined3d_context *context)
Definition: wined3d_gl.h:699

Referenced by set_glsl_shader_program(), and shader_glsl_load_program_resources().

◆ shader_glsl_load_samplers_range()

static void shader_glsl_load_samplers_range ( const struct wined3d_gl_info *  gl_info,
struct shader_glsl_priv *  priv,
GLuint  program_id,
const char *  prefix,
unsigned int  base,
unsigned int  count,
const unsigned int *  tex_unit_map 
)
static

Definition at line 871 of file glsl_shader.c.

874{
875 struct wined3d_string_buffer *sampler_name = string_buffer_get(&priv->string_buffers);
876 unsigned int i, mapped_unit;
877 GLint name_loc;
878
879 for (i = 0; i < count; ++i)
880 {
881 string_buffer_sprintf(sampler_name, "%s_sampler%u", prefix, i);
882 name_loc = GL_EXTCALL(glGetUniformLocation(program_id, sampler_name->buffer));
883 if (name_loc == -1)
884 continue;
885
886 mapped_unit = tex_unit_map ? tex_unit_map[base + i] : base + i;
887 if (mapped_unit == WINED3D_UNMAPPED_STAGE || mapped_unit >= gl_info->limits.combined_samplers)
888 {
889 ERR("Trying to load sampler %s on unsupported unit %u.\n", sampler_name->buffer, mapped_unit);
890 continue;
891 }
892
893 TRACE("Loading sampler %s on unit %u.\n", sampler_name->buffer, mapped_unit);
894 GL_EXTCALL(glUniform1i(name_loc, mapped_unit));
895 }
896 checkGLcall("Load sampler bindings");
897 string_buffer_release(&priv->string_buffers, sampler_name);
898}

Referenced by shader_glsl_load_samplers().

◆ shader_glsl_loop()

static void shader_glsl_loop ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_LOOP instruction in GLSL: Start a for() loop where src1.y is the initial value of aL, increment aL by src1.z for a total of src1.x iterations. Need to use a temporary variable for this operation.

Definition at line 5040 of file glsl_shader.c.

5041{
5042 struct wined3d_shader_parser_state *state = ins->ctx->state;
5043 struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
5044 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
5045 const struct wined3d_shader *shader = ins->ctx->shader;
5046 const struct wined3d_shader_lconst *constant;
5048 const unsigned int *control_values = NULL;
5049
5050 if (ins->ctx->reg_maps->shader_version.major < 4)
5051 {
5052 /* Try to hardcode the loop control parameters if possible. Direct3D 9
5053 * class hardware doesn't support real varying indexing, but Microsoft
5054 * designed this feature for Shader model 2.x+. If the loop control is
5055 * known at compile time, the GLSL compiler can unroll the loop, and
5056 * replace indirect addressing with direct addressing. */
5057 if (ins->src[1].reg.type == WINED3DSPR_CONSTINT)
5058 {
5060 {
5061 if (constant->idx == ins->src[1].reg.idx[0].offset)
5062 {
5063 control_values = constant->value;
5064 break;
5065 }
5066 }
5067 }
5068
5069 if (control_values)
5070 {
5071 struct wined3d_shader_loop_control loop_control;
5072 loop_control.count = control_values[0];
5073 loop_control.start = control_values[1];
5074 loop_control.step = (int)control_values[2];
5075
5076 if (loop_control.step > 0)
5077 {
5078 shader_addline(buffer, "for (aL%u = %u; aL%u < (%u * %d + %u); aL%u += %d)\n{\n",
5079 state->current_loop_depth, loop_control.start,
5080 state->current_loop_depth, loop_control.count, loop_control.step, loop_control.start,
5081 state->current_loop_depth, loop_control.step);
5082 }
5083 else if (loop_control.step < 0)
5084 {
5085 shader_addline(buffer, "for (aL%u = %u; aL%u > (%u * %d + %u); aL%u += %d)\n{\n",
5086 state->current_loop_depth, loop_control.start,
5087 state->current_loop_depth, loop_control.count, loop_control.step, loop_control.start,
5088 state->current_loop_depth, loop_control.step);
5089 }
5090 else
5091 {
5092 shader_addline(buffer, "for (aL%u = %u, tmpInt%u = 0; tmpInt%u < %u; tmpInt%u++)\n{\n",
5093 state->current_loop_depth, loop_control.start, state->current_loop_depth,
5094 state->current_loop_depth, loop_control.count,
5095 state->current_loop_depth);
5096 }
5097 }
5098 else
5099 {
5101 shader_glsl_get_register_name(&ins->src[1].reg, ins->src[1].reg.data_type, reg_name, NULL, ins->ctx);
5102
5103 shader_addline(buffer, "for (tmpInt%u = 0, aL%u = %s.y; tmpInt%u < %s.x; tmpInt%u++, aL%u += %s.z)\n{\n",
5104 state->current_loop_depth, state->current_loop_reg, reg_name->buffer,
5105 state->current_loop_depth, reg_name->buffer,
5106 state->current_loop_depth, state->current_loop_reg, reg_name->buffer);
5107
5109
5110 }
5111
5112 ++state->current_loop_reg;
5113 }
5114 else
5115 {
5116 shader_addline(buffer, "for (;;)\n{\n");
5117 }
5118
5119 ++state->current_loop_depth;
5120}
union constant::@270 value[4]

◆ shader_glsl_lrp()

static void shader_glsl_lrp ( const struct wined3d_shader_instruction *  ins)
static

The LRP instruction performs a component-wise linear interpolation between the second and third operands using the first operand as the blend factor. Equation: (dst = src2 + src0 * (src1 - src2)) This is equivalent to mix(src2, src1, src0);

Definition at line 4847 of file glsl_shader.c.

4848{
4849 struct glsl_src_param src0_param;
4850 struct glsl_src_param src1_param;
4851 struct glsl_src_param src2_param;
4852 DWORD write_mask;
4853
4854 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
4855
4856 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
4857 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
4858 shader_glsl_add_src_param(ins, &ins->src[2], write_mask, &src2_param);
4859
4860 shader_addline(ins->ctx->buffer, "mix(%s, %s, %s));\n",
4861 src2_param.param_str, src1_param.param_str, src0_param.param_str);
4862}

◆ shader_glsl_mad()

static void shader_glsl_mad ( const struct wined3d_shader_instruction *  ins)
static

GLSL code generation for WINED3DSIO_MAD: Multiply the first 2 opcodes, then add the last

Definition at line 4770 of file glsl_shader.c.

4771{
4772 struct glsl_src_param src0_param;
4773 struct glsl_src_param src1_param;
4774 struct glsl_src_param src2_param;
4775 DWORD write_mask;
4776
4777 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
4778 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
4779 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
4780 shader_glsl_add_src_param(ins, &ins->src[2], write_mask, &src2_param);
4781 shader_addline(ins->ctx->buffer, "(%s * %s) + %s);\n",
4782 src0_param.param_str, src1_param.param_str, src2_param.param_str);
4783}

◆ shader_glsl_map2gl()

static void shader_glsl_map2gl ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4218 of file glsl_shader.c.

4219{
4220 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4221 struct glsl_src_param src_param;
4222 const char *instruction;
4223 DWORD write_mask;
4224 unsigned i;
4225
4226 /* Determine the GLSL function to use based on the opcode */
4227 /* TODO: Possibly make this a table for faster lookups */
4228 switch (ins->handler_idx)
4229 {
4230 case WINED3DSIH_ABS: instruction = "abs"; break;
4231 case WINED3DSIH_BFREV: instruction = "bitfieldReverse"; break;
4232 case WINED3DSIH_COUNTBITS: instruction = "bitCount"; break;
4233 case WINED3DSIH_DSX: instruction = "dFdx"; break;
4234 case WINED3DSIH_DSX_COARSE: instruction = "dFdxCoarse"; break;
4235 case WINED3DSIH_DSX_FINE: instruction = "dFdxFine"; break;
4236 case WINED3DSIH_DSY: instruction = "dFdy"; break;
4237 case WINED3DSIH_DSY_COARSE: instruction = "dFdyCoarse"; break;
4238 case WINED3DSIH_DSY_FINE: instruction = "dFdyFine"; break;
4239 case WINED3DSIH_FIRSTBIT_HI: instruction = "findMSB"; break;
4240 case WINED3DSIH_FIRSTBIT_LO: instruction = "findLSB"; break;
4241 case WINED3DSIH_FIRSTBIT_SHI: instruction = "findMSB"; break;
4242 case WINED3DSIH_FRC: instruction = "fract"; break;
4243 case WINED3DSIH_IMAX: instruction = "max"; break;
4244 case WINED3DSIH_IMIN: instruction = "min"; break;
4245 case WINED3DSIH_MAX: instruction = "max"; break;
4246 case WINED3DSIH_MIN: instruction = "min"; break;
4247 case WINED3DSIH_ROUND_NE: instruction = "roundEven"; break;
4248 case WINED3DSIH_ROUND_NI: instruction = "floor"; break;
4249 case WINED3DSIH_ROUND_PI: instruction = "ceil"; break;
4250 case WINED3DSIH_ROUND_Z: instruction = "trunc"; break;
4251 case WINED3DSIH_SQRT: instruction = "sqrt"; break;
4252 case WINED3DSIH_UMAX: instruction = "max"; break;
4253 case WINED3DSIH_UMIN: instruction = "min"; break;
4254 default: instruction = "";
4255 ERR("Opcode %s not yet handled in GLSL.\n", debug_d3dshaderinstructionhandler(ins->handler_idx));
4256 break;
4257 }
4258
4259 write_mask = shader_glsl_append_dst(buffer, ins);
4260
4261 /* In D3D bits are numbered from the most significant bit. */
4263 shader_addline(buffer, "31 - ");
4265
4266 if (ins->src_count)
4267 {
4268 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src_param);
4269 shader_addline(buffer, "%s", src_param.param_str);
4270 for (i = 1; i < ins->src_count; ++i)
4271 {
4272 shader_glsl_add_src_param(ins, &ins->src[i], write_mask, &src_param);
4273 shader_addline(buffer, ", %s", src_param.param_str);
4274 }
4275 }
4276
4277 shader_addline(buffer, "));\n");
4278}
@ WINED3DSIH_DSX_COARSE
@ WINED3DSIH_DSX_FINE
@ WINED3DSIH_FIRSTBIT_HI
@ WINED3DSIH_ABS
@ WINED3DSIH_ROUND_Z
@ WINED3DSIH_DSY_COARSE
@ WINED3DSIH_IMIN
@ WINED3DSIH_UMAX
@ WINED3DSIH_ROUND_PI
@ WINED3DSIH_UMIN
@ WINED3DSIH_SQRT
@ WINED3DSIH_BFREV
@ WINED3DSIH_FRC
@ WINED3DSIH_DSX
@ WINED3DSIH_COUNTBITS
@ WINED3DSIH_MIN
@ WINED3DSIH_IMAX
@ WINED3DSIH_DSY
@ WINED3DSIH_ROUND_NI
@ WINED3DSIH_FIRSTBIT_SHI
@ WINED3DSIH_FIRSTBIT_LO
@ WINED3DSIH_ROUND_NE
@ WINED3DSIH_MAX
@ WINED3DSIH_DSY_FINE

◆ shader_glsl_map_tex_unit()

static unsigned int shader_glsl_map_tex_unit ( const struct wined3d_context *  context,
const struct wined3d_shader_version *  shader_version,
unsigned int  sampler_idx 
)
static

Definition at line 900 of file glsl_shader.c.

902{
903 const struct wined3d_context_gl *context_gl = wined3d_context_gl_const(context);
904 const unsigned int *tex_unit_map;
905 unsigned int base, count;
906
907 tex_unit_map = wined3d_context_gl_get_tex_unit_mapping(context_gl, shader_version, &base, &count);
908 if (sampler_idx >= count)
910 if (!tex_unit_map)
911 return base + sampler_idx;
912 return tex_unit_map[base + sampler_idx];
913}
unsigned int tex_unit_map[WINED3D_MAX_COMBINED_SAMPLERS]
Definition: wined3d_gl.h:676

Referenced by shader_glsl_append_sampler_binding_qualifier().

◆ shader_glsl_mnxn()

static void shader_glsl_mnxn ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4787 of file glsl_shader.c.

4788{
4789 int i;
4790 int nComponents = 0;
4791 struct wined3d_shader_dst_param tmp_dst = {{0}};
4792 struct wined3d_shader_src_param tmp_src[2] = {{{0}}};
4793 struct wined3d_shader_instruction tmp_ins;
4794
4795 memset(&tmp_ins, 0, sizeof(tmp_ins));
4796
4797 /* Set constants for the temporary argument */
4798 tmp_ins.ctx = ins->ctx;
4799 tmp_ins.dst_count = 1;
4800 tmp_ins.dst = &tmp_dst;
4801 tmp_ins.src_count = 2;
4802 tmp_ins.src = tmp_src;
4803
4804 switch(ins->handler_idx)
4805 {
4806 case WINED3DSIH_M4x4:
4807 nComponents = 4;
4808 tmp_ins.handler_idx = WINED3DSIH_DP4;
4809 break;
4810 case WINED3DSIH_M4x3:
4811 nComponents = 3;
4812 tmp_ins.handler_idx = WINED3DSIH_DP4;
4813 break;
4814 case WINED3DSIH_M3x4:
4815 nComponents = 4;
4816 tmp_ins.handler_idx = WINED3DSIH_DP3;
4817 break;
4818 case WINED3DSIH_M3x3:
4819 nComponents = 3;
4820 tmp_ins.handler_idx = WINED3DSIH_DP3;
4821 break;
4822 case WINED3DSIH_M3x2:
4823 nComponents = 2;
4824 tmp_ins.handler_idx = WINED3DSIH_DP3;
4825 break;
4826 default:
4827 break;
4828 }
4829
4830 tmp_dst = ins->dst[0];
4831 tmp_src[0] = ins->src[0];
4832 tmp_src[1] = ins->src[1];
4833 for (i = 0; i < nComponents; ++i)
4834 {
4835 tmp_dst.write_mask = WINED3DSP_WRITEMASK_0 << i;
4836 shader_glsl_dot(&tmp_ins);
4837 ++tmp_src[1].reg.idx[0].offset;
4838 }
4839}
static void shader_glsl_dot(const struct wined3d_shader_instruction *ins)
Definition: glsl_shader.c:4133
@ WINED3DSIH_M3x3
@ WINED3DSIH_M3x4
@ WINED3DSIH_M3x2
@ WINED3DSIH_M4x3
@ WINED3DSIH_M4x4

◆ shader_glsl_mov()

static void shader_glsl_mov ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4080 of file glsl_shader.c.

4081{
4082 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
4083 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4084 const struct wined3d_gl_info *gl_info = priv->gl_info;
4085 struct glsl_src_param src0_param;
4086 DWORD write_mask;
4087
4088 write_mask = shader_glsl_append_dst(buffer, ins);
4089 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
4090
4091 /* In vs_1_1 WINED3DSIO_MOV can write to the address register. In later
4092 * shader versions WINED3DSIO_MOVA is used for this. */
4093 if (ins->ctx->reg_maps->shader_version.major == 1
4094 && ins->ctx->reg_maps->shader_version.type == WINED3D_SHADER_TYPE_VERTEX
4095 && ins->dst[0].reg.type == WINED3DSPR_ADDR)
4096 {
4097 /* This is a simple floor() */
4098 unsigned int mask_size = shader_glsl_get_write_mask_size(write_mask);
4099 if (mask_size > 1) {
4100 shader_addline(buffer, "ivec%d(floor(%s)));\n", mask_size, src0_param.param_str);
4101 } else {
4102 shader_addline(buffer, "int(floor(%s)));\n", src0_param.param_str);
4103 }
4104 }
4105 else if (ins->handler_idx == WINED3DSIH_MOVA)
4106 {
4107 unsigned int mask_size = shader_glsl_get_write_mask_size(write_mask);
4108
4109 if (shader_glsl_get_version(gl_info) >= 130 || gl_info->supported[EXT_GPU_SHADER4])
4110 {
4111 if (mask_size > 1)
4112 shader_addline(buffer, "ivec%d(round(%s)));\n", mask_size, src0_param.param_str);
4113 else
4114 shader_addline(buffer, "int(round(%s)));\n", src0_param.param_str);
4115 }
4116 else
4117 {
4118 if (mask_size > 1)
4119 shader_addline(buffer, "ivec%d(floor(abs(%s) + vec%d(0.5)) * sign(%s)));\n",
4120 mask_size, src0_param.param_str, mask_size, src0_param.param_str);
4121 else
4122 shader_addline(buffer, "int(floor(abs(%s) + 0.5) * sign(%s)));\n",
4123 src0_param.param_str, src0_param.param_str);
4124 }
4125 }
4126 else
4127 {
4128 shader_addline(buffer, "%s);\n", src0_param.param_str);
4129 }
4130}
@ WINED3DSIH_MOVA
@ WINED3DSPR_ADDR

◆ shader_glsl_mul_extended()

static void shader_glsl_mul_extended ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4013 of file glsl_shader.c.

4014{
4015 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4016 struct glsl_src_param src0_param;
4017 struct glsl_src_param src1_param;
4018 DWORD write_mask;
4019
4020 /* If we have ARB_gpu_shader5, we can use imulExtended() / umulExtended().
4021 * If not, we can emulate it. */
4022 if (ins->dst[0].reg.type != WINED3DSPR_NULL)
4023 FIXME("64-bit integer multiplies not implemented.\n");
4024
4025 if (ins->dst[1].reg.type != WINED3DSPR_NULL)
4026 {
4027 write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], 1, ins->dst[1].reg.data_type);
4028 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
4029 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
4030
4031 shader_addline(ins->ctx->buffer, "%s * %s);\n",
4032 src0_param.param_str, src1_param.param_str);
4033 }
4034}

◆ shader_glsl_nop()

static void shader_glsl_nop ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4358 of file glsl_shader.c.

4358{}

◆ shader_glsl_nrm()

static void shader_glsl_nrm ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4360 of file glsl_shader.c.

4361{
4362 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4363 struct glsl_src_param src_param;
4364 unsigned int mask_size;
4365 DWORD write_mask;
4366 char dst_mask[6];
4367
4368 write_mask = shader_glsl_get_write_mask(ins->dst, dst_mask);
4369 mask_size = shader_glsl_get_write_mask_size(write_mask);
4370 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src_param);
4371
4372 if (mask_size > 3)
4373 shader_addline(buffer, "tmp0.x = dot(vec3(%s), vec3(%s));\n",
4374 src_param.param_str, src_param.param_str);
4375 else
4376 shader_addline(buffer, "tmp0.x = dot(%s, %s);\n",
4377 src_param.param_str, src_param.param_str);
4379
4380 shader_addline(buffer, "tmp0.x == 0.0 ? %s : (%s * inversesqrt(tmp0.x)));\n",
4381 src_param.param_str, src_param.param_str);
4382}

◆ shader_glsl_pointsize_uniform()

static void shader_glsl_pointsize_uniform ( struct wined3d_context_gl *  context_gl,
const struct wined3d_state *  state,
struct glsl_shader_prog_link *  prog 
)
static

Definition at line 1658 of file glsl_shader.c.

1660{
1661 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
1662 const struct wined3d_ffp_vs_constants *constants;
1663 float min, max;
1664
1666 context_gl->c.device->push_constants[WINED3D_PUSH_CONSTANTS_VS_FFP], &context_gl->c);
1667
1668 get_pointsize_minmax(&context_gl->c, state, &min, &max);
1669
1670 GL_EXTCALL(glUniform1f(prog->vs.pointsize_min_location, min));
1671 checkGLcall("glUniform1f");
1672 GL_EXTCALL(glUniform1f(prog->vs.pointsize_max_location, max));
1673 checkGLcall("glUniform1f");
1674
1675 GL_EXTCALL(glUniform1f(prog->vs.pointsize_location, int_to_float(state->render_states[WINED3D_RS_POINTSIZE])));
1676 checkGLcall("glUniform1f");
1677 GL_EXTCALL(glUniform1f(prog->vs.pointsize_c_att_location, constants->point.scale_const));
1678 checkGLcall("glUniform1f");
1679 GL_EXTCALL(glUniform1f(prog->vs.pointsize_l_att_location, constants->point.scale_linear));
1680 checkGLcall("glUniform1f");
1681 GL_EXTCALL(glUniform1f(prog->vs.pointsize_q_att_location, constants->point.scale_quad));
1682 checkGLcall("glUniform1f");
1683}
void get_pointsize_minmax(const struct wined3d_context *context, const struct wined3d_state *state, float *out_min, float *out_max)
Definition: utils.c:5684
@ WINED3D_RS_POINTSIZE
Definition: wined3d.h:362
static float int_to_float(uint32_t i)

Referenced by shader_glsl_load_constants().

◆ shader_glsl_pow()

static void shader_glsl_pow ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4191 of file glsl_shader.c.

4192{
4193 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4194 struct glsl_src_param src0_param;
4195 struct glsl_src_param src1_param;
4196 DWORD dst_write_mask;
4197 unsigned int dst_size;
4198
4199 dst_write_mask = shader_glsl_append_dst(buffer, ins);
4200 dst_size = shader_glsl_get_write_mask_size(dst_write_mask);
4201
4202 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
4203 shader_glsl_add_src_param(ins, &ins->src[1], WINED3DSP_WRITEMASK_0, &src1_param);
4204
4205 if (dst_size > 1)
4206 {
4207 shader_addline(buffer, "vec%u(%s == 0.0 ? 1.0 : pow(abs(%s), %s)));\n",
4208 dst_size, src1_param.param_str, src0_param.param_str, src1_param.param_str);
4209 }
4210 else
4211 {
4212 shader_addline(buffer, "%s == 0.0 ? 1.0 : pow(abs(%s), %s));\n",
4213 src1_param.param_str, src0_param.param_str, src1_param.param_str);
4214 }
4215}

◆ shader_glsl_precompile()

static void shader_glsl_precompile ( void *  shader_priv,
struct wined3d_shader *  shader 
)
static

Definition at line 10814 of file glsl_shader.c.

10815{
10816 struct wined3d_device *device = shader->device;
10817 struct wined3d_context *context;
10818
10819 if (shader->reg_maps.shader_version.type == WINED3D_SHADER_TYPE_COMPUTE)
10820 {
10824 }
10825}

◆ shader_glsl_release_sample_function()

◆ shader_glsl_relop()

static void shader_glsl_relop ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 3929 of file glsl_shader.c.

3930{
3931 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
3932 struct glsl_src_param src0_param;
3933 struct glsl_src_param src1_param;
3934 unsigned int mask_size;
3935 DWORD write_mask;
3936 const char *op;
3937
3938 write_mask = shader_glsl_append_dst(buffer, ins);
3939 mask_size = shader_glsl_get_write_mask_size(write_mask);
3940 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
3941 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
3942
3943 if (mask_size > 1)
3944 {
3945 switch (ins->handler_idx)
3946 {
3947 case WINED3DSIH_EQ: op = "equal"; break;
3948 case WINED3DSIH_IEQ: op = "equal"; break;
3949 case WINED3DSIH_GE: op = "greaterThanEqual"; break;
3950 case WINED3DSIH_IGE: op = "greaterThanEqual"; break;
3951 case WINED3DSIH_UGE: op = "greaterThanEqual"; break;
3952 case WINED3DSIH_LT: op = "lessThan"; break;
3953 case WINED3DSIH_ILT: op = "lessThan"; break;
3954 case WINED3DSIH_ULT: op = "lessThan"; break;
3955 case WINED3DSIH_NE: op = "notEqual"; break;
3956 case WINED3DSIH_INE: op = "notEqual"; break;
3957 default:
3958 op = "<unhandled operator>";
3959 ERR("Unhandled opcode %#x.\n", ins->handler_idx);
3960 break;
3961 }
3962
3963 shader_addline(buffer, "uvec%u(%s(%s, %s)) * 0xffffffffu);\n",
3964 mask_size, op, src0_param.param_str, src1_param.param_str);
3965 }
3966 else
3967 {
3968 switch (ins->handler_idx)
3969 {
3970 case WINED3DSIH_EQ: op = "=="; break;
3971 case WINED3DSIH_IEQ: op = "=="; break;
3972 case WINED3DSIH_GE: op = ">="; break;
3973 case WINED3DSIH_IGE: op = ">="; break;
3974 case WINED3DSIH_UGE: op = ">="; break;
3975 case WINED3DSIH_LT: op = "<"; break;
3976 case WINED3DSIH_ILT: op = "<"; break;
3977 case WINED3DSIH_ULT: op = "<"; break;
3978 case WINED3DSIH_NE: op = "!="; break;
3979 case WINED3DSIH_INE: op = "!="; break;
3980 default:
3981 op = "<unhandled operator>";
3982 ERR("Unhandled opcode %#x.\n", ins->handler_idx);
3983 break;
3984 }
3985
3986 shader_addline(buffer, "%s %s %s ? 0xffffffffu : 0u);\n",
3987 src0_param.param_str, op, src1_param.param_str);
3988 }
3989}
@ WINED3DSIH_ULT
@ WINED3DSIH_IEQ
@ WINED3DSIH_EQ
@ WINED3DSIH_ILT
@ WINED3DSIH_GE
@ WINED3DSIH_IGE
@ WINED3DSIH_LT
@ WINED3DSIH_INE
@ WINED3DSIH_UGE
@ WINED3DSIH_NE

◆ shader_glsl_rep()

static void shader_glsl_rep ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5140 of file glsl_shader.c.

5141{
5142 struct wined3d_shader_parser_state *state = ins->ctx->state;
5143 const struct wined3d_shader *shader = ins->ctx->shader;
5144 const struct wined3d_shader_lconst *constant;
5145 struct glsl_src_param src0_param;
5146 const unsigned int *control_values = NULL;
5147
5148 /* Try to hardcode local values to help the GLSL compiler to unroll and optimize the loop */
5149 if (ins->src[0].reg.type == WINED3DSPR_CONSTINT)
5150 {
5152 {
5153 if (constant->idx == ins->src[0].reg.idx[0].offset)
5154 {
5155 control_values = constant->value;
5156 break;
5157 }
5158 }
5159 }
5160
5161 if (control_values)
5162 {
5163 shader_addline(ins->ctx->buffer, "for (tmpInt%d = 0; tmpInt%d < %d; tmpInt%d++) {\n",
5164 state->current_loop_depth, state->current_loop_depth,
5165 control_values[0], state->current_loop_depth);
5166 }
5167 else
5168 {
5169 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
5170 shader_addline(ins->ctx->buffer, "for (tmpInt%d = 0; tmpInt%d < %s; tmpInt%d++) {\n",
5171 state->current_loop_depth, state->current_loop_depth,
5172 src0_param.param_str, state->current_loop_depth);
5173 }
5174
5175 ++state->current_loop_depth;
5176}

◆ shader_glsl_resinfo()

static void shader_glsl_resinfo ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 6032 of file glsl_shader.c.

6033{
6034 const struct wined3d_shader_version *version = &ins->ctx->reg_maps->shader_version;
6035 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
6036 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
6037 const struct wined3d_gl_info *gl_info = priv->gl_info;
6038 enum wined3d_shader_resource_type resource_type;
6040 unsigned int resource_idx, bind_idx, i;
6041 enum wined3d_data_type dst_data_type;
6042 struct glsl_src_param lod_param;
6043 BOOL supports_mipmaps;
6044 char dst_swizzle[6];
6045 DWORD write_mask;
6046
6047 dst_data_type = ins->dst[0].reg.data_type;
6048 if (ins->flags == WINED3DSI_RESINFO_UINT)
6049 dst_data_type = WINED3D_DATA_UINT;
6050 else if (ins->flags)
6051 FIXME("Unhandled flags %#x.\n", ins->flags);
6052
6053 reg_type = ins->src[1].reg.type;
6054 resource_idx = ins->src[1].reg.idx[0].offset;
6055 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &lod_param);
6057 {
6058 resource_type = ins->ctx->reg_maps->resource_info[resource_idx].type;
6059 bind_idx = shader_glsl_find_sampler(&ins->ctx->reg_maps->sampler_map,
6060 resource_idx, WINED3D_SAMPLER_DEFAULT);
6061 }
6062 else
6063 {
6064 resource_type = ins->ctx->reg_maps->uav_resource_info[resource_idx].type;
6065 bind_idx = resource_idx;
6066 }
6067
6068 if (resource_type >= ARRAY_SIZE(resource_type_info))
6069 {
6070 ERR("Unexpected resource type %#x.\n", resource_type);
6071 return;
6072 }
6073
6074 write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, dst_data_type);
6075 shader_glsl_get_swizzle(&ins->src[1], FALSE, write_mask, dst_swizzle);
6076
6077 if (dst_data_type == WINED3D_DATA_UINT)
6078 shader_addline(buffer, "uvec4(");
6079 else
6080 shader_addline(buffer, "vec4(");
6081
6083 {
6084 shader_addline(buffer, "textureSize(%s_sampler%u",
6085 shader_glsl_get_prefix(version->type), bind_idx);
6086 }
6087 else
6088 {
6089 shader_addline(buffer, "imageSize(%s_image%u",
6090 shader_glsl_get_prefix(version->type), bind_idx);
6091 }
6092
6093 supports_mipmaps = is_mipmapped(resource_type) && reg_type != WINED3DSPR_UAV;
6094 if (supports_mipmaps)
6095 shader_addline(buffer, ", %s", lod_param.param_str);
6096 shader_addline(buffer, "), ");
6097
6098 for (i = 0; i < 3 - resource_type_info[resource_type].resinfo_size; ++i)
6099 shader_addline(buffer, "0, ");
6100
6101 if (supports_mipmaps)
6102 {
6103 if (gl_info->supported[ARB_TEXTURE_QUERY_LEVELS])
6104 {
6105 shader_addline(buffer, "textureQueryLevels(%s_sampler%u)",
6106 shader_glsl_get_prefix(version->type), bind_idx);
6107 }
6108 else
6109 {
6110 FIXME("textureQueryLevels is not supported, returning 1 level.\n");
6111 shader_addline(buffer, "1");
6112 }
6113 }
6114 else
6115 {
6116 shader_addline(buffer, "1");
6117 }
6118
6119 shader_addline(buffer, ")%s);\n", dst_swizzle);
6120}
enum vkd3d_shader_register_type reg_type
Definition: spirv.c:4885
#define WINED3DSI_RESINFO_UINT
wined3d_shader_register_type

◆ shader_glsl_ret()

static void shader_glsl_ret ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5325 of file glsl_shader.c.

5326{
5327 const struct wined3d_shader_version *version = &ins->ctx->shader->reg_maps.shader_version;
5328
5329 if (version->major >= 4 && !ins->ctx->state->in_subroutine)
5330 {
5332 shader_addline(ins->ctx->buffer, "return;\n");
5333 }
5334}

◆ shader_glsl_sample()

static void shader_glsl_sample ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 6245 of file glsl_shader.c.

6246{
6247 const char *lod_param_str = NULL, *dx_param_str = NULL, *dy_param_str = NULL;
6248 struct glsl_src_param coord_param, lod_param, dx_param, dy_param;
6249 unsigned int resource_idx, sampler_idx, sampler_bind_idx;
6250 struct glsl_sample_function sample_function;
6251 DWORD flags = 0;
6252
6259
6260 resource_idx = ins->src[1].reg.idx[0].offset;
6261 sampler_idx = ins->src[2].reg.idx[0].offset;
6262
6263 shader_glsl_get_sample_function(ins->ctx, resource_idx, sampler_idx, flags, &sample_function);
6264 shader_glsl_add_src_param(ins, &ins->src[0], sample_function.coord_mask, &coord_param);
6265
6266 switch (ins->handler_idx)
6267 {
6268 case WINED3DSIH_SAMPLE:
6269 break;
6271 shader_glsl_add_src_param(ins, &ins->src[3], WINED3DSP_WRITEMASK_0, &lod_param);
6272 lod_param_str = lod_param.param_str;
6273 break;
6275 shader_glsl_add_src_param(ins, &ins->src[3], sample_function.deriv_mask, &dx_param);
6276 shader_glsl_add_src_param(ins, &ins->src[4], sample_function.deriv_mask, &dy_param);
6277 dx_param_str = dx_param.param_str;
6278 dy_param_str = dy_param.param_str;
6279 break;
6281 shader_glsl_add_src_param(ins, &ins->src[3], WINED3DSP_WRITEMASK_0, &lod_param);
6282 lod_param_str = lod_param.param_str;
6283 break;
6284 default:
6285 ERR("Unhandled opcode %s.\n", debug_d3dshaderinstructionhandler(ins->handler_idx));
6286 break;
6287 }
6288
6289 sampler_bind_idx = shader_glsl_find_sampler(&ins->ctx->reg_maps->sampler_map, resource_idx, sampler_idx);
6290 shader_glsl_gen_sample_code(ins, sampler_bind_idx, &sample_function, ins->src[1].swizzle,
6291 dx_param_str, dy_param_str, lod_param_str, &ins->texel_offset, "%s", coord_param.param_str);
6292 shader_glsl_release_sample_function(ins->ctx, &sample_function);
6293}
@ WINED3DSIH_SAMPLE_B
@ WINED3DSIH_SAMPLE_LOD
@ WINED3DSIH_SAMPLE_GRAD
@ WINED3DSIH_SAMPLE

◆ shader_glsl_sample_c()

static void shader_glsl_sample_c ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 6325 of file glsl_shader.c.

6326{
6327 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
6328 unsigned int resource_idx, sampler_idx, sampler_bind_idx;
6329 const struct wined3d_shader_resource_info *resource_info;
6330 const struct wined3d_gl_info *gl_info = priv->gl_info;
6331 struct glsl_src_param coord_param, compare_param;
6332 struct glsl_sample_function sample_function;
6333 const char *lod_param = NULL;
6334 unsigned int coord_size;
6335 DWORD flags = 0;
6336
6338 {
6339 lod_param = "0";
6341 }
6342
6345
6346 if (!(resource_info = shader_glsl_get_resource_info(ins, &ins->src[1].reg)))
6347 return;
6348 resource_idx = ins->src[1].reg.idx[0].offset;
6349 sampler_idx = ins->src[2].reg.idx[0].offset;
6350
6351 shader_glsl_get_sample_function(ins->ctx, resource_idx, sampler_idx, flags, &sample_function);
6352 coord_size = shader_glsl_get_write_mask_size(sample_function.coord_mask);
6353 shader_glsl_add_src_param(ins, &ins->src[0], sample_function.coord_mask >> 1, &coord_param);
6354 shader_glsl_add_src_param(ins, &ins->src[3], WINED3DSP_WRITEMASK_0, &compare_param);
6355 sampler_bind_idx = shader_glsl_find_sampler(&ins->ctx->reg_maps->sampler_map, resource_idx, sampler_idx);
6357 && !gl_info->supported[EXT_TEXTURE_SHADOW_LOD]
6358 && (resource_info->type == WINED3D_SHADER_RESOURCE_TEXTURE_2DARRAY
6359 || resource_info->type == WINED3D_SHADER_RESOURCE_TEXTURE_CUBE))
6360 {
6361 shader_glsl_gen_sample_c_lz_emulation(ins, sampler_bind_idx, &sample_function,
6362 coord_size, coord_param.param_str, compare_param.param_str);
6363 }
6364 else
6365 {
6366 shader_glsl_gen_sample_code(ins, sampler_bind_idx, &sample_function, WINED3DSP_NOSWIZZLE,
6367 NULL, NULL, lod_param, &ins->texel_offset, "vec%u(%s, %s)",
6368 coord_size, coord_param.param_str, compare_param.param_str);
6369 }
6370 shader_glsl_release_sample_function(ins->ctx, &sample_function);
6371}
static void shader_glsl_gen_sample_c_lz_emulation(const struct wined3d_shader_instruction *ins, unsigned int sampler_bind_idx, const struct glsl_sample_function *sample_function, unsigned int coord_size, const char *coord_param, const char *ref_param)
Definition: glsl_shader.c:6298
@ WINED3DSIH_SAMPLE_C_LZ

◆ shader_glsl_sample_info()

static void shader_glsl_sample_info ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 6122 of file glsl_shader.c.

6123{
6124 const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps;
6125 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
6126 const struct wined3d_gl_info *gl_info = priv->gl_info;
6127 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
6128 const struct wined3d_shader_dst_param *dst = ins->dst;
6129 const struct wined3d_shader_src_param *src = ins->src;
6130 enum wined3d_shader_resource_type resource_type;
6131 enum wined3d_data_type dst_data_type;
6132 unsigned int resource_idx, bind_idx;
6133 char dst_swizzle[6];
6134 DWORD write_mask;
6135
6136 dst_data_type = dst->reg.data_type;
6138 dst_data_type = WINED3D_DATA_UINT;
6139 else if (ins->flags)
6140 FIXME("Unhandled flags %#x.\n", ins->flags);
6141
6142 write_mask = shader_glsl_append_dst_ext(buffer, ins, dst, 0, dst_data_type);
6143 shader_glsl_get_swizzle(src, FALSE, write_mask, dst_swizzle);
6144
6145 if (dst_data_type == WINED3D_DATA_UINT)
6146 shader_addline(buffer, "uvec4(");
6147 else
6148 shader_addline(buffer, "vec4(");
6149
6150 if (src->reg.type == WINED3DSPR_RASTERIZER)
6151 {
6152 if (gl_info->supported[ARB_SAMPLE_SHADING])
6153 {
6154 shader_addline(buffer, "gl_NumSamples");
6155 }
6156 else
6157 {
6158 FIXME("OpenGL implementation does not support ARB_sample_shading.\n");
6159 shader_addline(buffer, "1");
6160 }
6161 }
6162 else
6163 {
6164 resource_idx = src->reg.idx[0].offset;
6165 resource_type = reg_maps->resource_info[resource_idx].type;
6166 if (resource_type >= ARRAY_SIZE(resource_type_info))
6167 {
6168 ERR("Unexpected resource type %#x.\n", resource_type);
6169 return;
6170 }
6171 bind_idx = shader_glsl_find_sampler(&reg_maps->sampler_map, resource_idx, WINED3D_SAMPLER_DEFAULT);
6172
6174 {
6175 shader_addline(buffer, "textureSamples(%s_sampler%u)",
6176 shader_glsl_get_prefix(reg_maps->shader_version.type), bind_idx);
6177 }
6178 else
6179 {
6180 FIXME("textureSamples() is not supported.\n");
6181 shader_addline(buffer, "1");
6182 }
6183 }
6184
6185 shader_addline(buffer, ", 0, 0, 0)%s);\n", dst_swizzle);
6186}
#define WINED3DSI_SAMPLE_INFO_UINT
@ WINED3DSPR_RASTERIZER

◆ shader_glsl_scalar_op()

static void shader_glsl_scalar_op ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4384 of file glsl_shader.c.

4385{
4386 DWORD shader_version = WINED3D_SHADER_VERSION(ins->ctx->reg_maps->shader_version.major,
4387 ins->ctx->reg_maps->shader_version.minor);
4388 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4389 struct glsl_src_param src0_param;
4390 const char *prefix, *suffix;
4391 unsigned int dst_size;
4392 DWORD dst_write_mask;
4393
4394 dst_write_mask = shader_glsl_append_dst(buffer, ins);
4395 dst_size = shader_glsl_get_write_mask_size(dst_write_mask);
4396
4397 if (shader_version < WINED3D_SHADER_VERSION(4, 0))
4398 dst_write_mask = WINED3DSP_WRITEMASK_3;
4399
4400 shader_glsl_add_src_param(ins, &ins->src[0], dst_write_mask, &src0_param);
4401
4402 switch (ins->handler_idx)
4403 {
4404 case WINED3DSIH_EXP:
4405 case WINED3DSIH_EXPP:
4406 prefix = "exp2(";
4407 suffix = ")";
4408 break;
4409
4410 case WINED3DSIH_LOG:
4411 case WINED3DSIH_LOGP:
4412 prefix = "log2(abs(";
4413 suffix = "))";
4414 break;
4415
4416 case WINED3DSIH_RCP:
4417 prefix = "1.0 / ";
4418 suffix = "";
4419 break;
4420
4421 case WINED3DSIH_RSQ:
4422 prefix = "inversesqrt(abs(";
4423 suffix = "))";
4424 break;
4425
4426 default:
4427 prefix = "";
4428 suffix = "";
4429 FIXME("Unhandled instruction %#x.\n", ins->handler_idx);
4430 break;
4431 }
4432
4433 if (dst_size > 1 && shader_version < WINED3D_SHADER_VERSION(4, 0))
4434 shader_addline(buffer, "vec%u(%s%s%s));\n", dst_size, prefix, src0_param.param_str, suffix);
4435 else
4436 shader_addline(buffer, "%s%s%s);\n", prefix, src0_param.param_str, suffix);
4437}
@ WINED3DSIH_RCP
@ WINED3DSIH_EXP
@ WINED3DSIH_LOG
@ WINED3DSIH_RSQ
@ WINED3DSIH_EXPP
@ WINED3DSIH_LOGP

Referenced by shader_glsl_expp().

◆ shader_glsl_setup_sm3_rasterizer_input()

static void shader_glsl_setup_sm3_rasterizer_input ( struct shader_glsl_priv *  priv,
const struct wined3d_gl_info *  gl_info,
const unsigned int *  map,
const struct wined3d_shader_signature *  input_signature,
const struct wined3d_shader_reg_maps *  reg_maps_in,
unsigned int  input_count,
const struct wined3d_shader_signature *  output_signature,
const struct wined3d_shader_reg_maps *  reg_maps_out,
BOOL  per_vertex_point_size 
)
static

Definition at line 7247 of file glsl_shader.c.

7253{
7255 const char *semantic_name;
7256 unsigned int semantic_idx;
7257 char reg_mask[6];
7258 unsigned int i;
7259
7260 /* First, sort out position and point size system values. */
7261 for (i = 0; i < output_signature->element_count; ++i)
7262 {
7263 const struct wined3d_shader_signature_element *output = &output_signature->elements[i];
7264
7265 if (!(reg_maps_out->output_registers & (1u << output->register_idx)))
7266 continue;
7267
7268 if (output->stream_idx)
7269 continue;
7270
7271 semantic_name = output->semantic_name;
7272 semantic_idx = output->semantic_idx;
7273 shader_glsl_write_mask_to_str(output->mask, reg_mask);
7274
7276 {
7277 shader_addline(buffer, "gl_Position%s = outputs[%u]%s;\n",
7278 reg_mask, output->register_idx, reg_mask);
7279 }
7280 else if (shader_match_semantic(semantic_name, WINED3D_DECL_USAGE_PSIZE) && per_vertex_point_size)
7281 {
7282 shader_addline(buffer, "gl_PointSize = clamp(outputs[%u].%c, "
7283 "ffp_point.size_min, ffp_point.size_max);\n", output->register_idx, reg_mask[1]);
7284 }
7286 {
7287 shader_addline(buffer, "gl_Layer = floatBitsToInt(outputs[%u])%s;\n",
7288 output->register_idx, reg_mask);
7289 }
7291 {
7292 shader_addline(buffer, "gl_ViewportIndex = floatBitsToInt(outputs[%u])%s;\n",
7293 output->register_idx, reg_mask);
7294 }
7295 else if (output->sysval_semantic == WINED3D_SV_CLIP_DISTANCE)
7296 {
7298 }
7299 else if (output->sysval_semantic == WINED3D_SV_CULL_DISTANCE)
7300 {
7302 }
7303 else if (output->sysval_semantic)
7304 {
7305 FIXME("Unhandled sysval semantic %#x.\n", output->sysval_semantic);
7306 }
7307 }
7308
7309 /* Then, setup the pixel shader input. */
7310 if (reg_maps_out->shader_version.major < 4)
7311 shader_glsl_setup_vs3_output(priv, gl_info, map, input_signature, reg_maps_in,
7312 output_signature, reg_maps_out);
7313 else
7314 shader_glsl_setup_sm4_shader_output(priv, input_count, output_signature, reg_maps_out, "shader_out", TRUE);
7315}
static void shader_glsl_generate_clip_or_cull_distances(struct wined3d_string_buffer *buffer, const struct wined3d_shader_signature_element *element, DWORD clip_or_cull_distance_mask)
Definition: glsl_shader.c:7225
static void shader_glsl_setup_vs3_output(struct shader_glsl_priv *priv, const struct wined3d_gl_info *gl_info, const unsigned int *map, const struct wined3d_shader_signature *input_signature, const struct wined3d_shader_reg_maps *reg_maps_in, const struct wined3d_shader_signature *output_signature, const struct wined3d_shader_reg_maps *reg_maps_out)
Definition: glsl_shader.c:7090
enum wined3d_sysval_semantic sysval_semantic
@ WINED3D_SV_CULL_DISTANCE

Referenced by shader_glsl_generate_sm4_output_setup(), and shader_glsl_generate_vs3_rasterizer_input_setup().

◆ shader_glsl_setup_sm4_shader_output()

static void shader_glsl_setup_sm4_shader_output ( struct shader_glsl_priv *  priv,
unsigned int  input_count,
const struct wined3d_shader_signature *  output_signature,
const struct wined3d_shader_reg_maps *  reg_maps_out,
const char *  output_variable_name,
BOOL  rasterizer_setup 
)
static

Definition at line 7195 of file glsl_shader.c.

7199{
7201 char reg_mask[6];
7202 unsigned int i;
7203
7204 for (i = 0; i < output_signature->element_count; ++i)
7205 {
7206 const struct wined3d_shader_signature_element *output = &output_signature->elements[i];
7207
7208 if (!(reg_maps_out->output_registers & (1u << output->register_idx)))
7209 continue;
7210
7211 if (output->stream_idx)
7212 continue;
7213
7214 if (output->register_idx >= input_count)
7215 continue;
7216
7217 shader_glsl_write_mask_to_str(output->mask, reg_mask);
7218
7220 rasterizer_setup ? "%s.reg%u%s = outputs[%u]%s;\n" : "%s.reg[%u]%s = outputs[%u]%s;\n",
7221 output_variable_name, output->register_idx, reg_mask, output->register_idx, reg_mask);
7222 }
7223}

Referenced by shader_glsl_generate_hull_shader(), shader_glsl_generate_sm4_output_setup(), and shader_glsl_setup_sm3_rasterizer_input().

◆ shader_glsl_setup_vs3_output()

static void shader_glsl_setup_vs3_output ( struct shader_glsl_priv *  priv,
const struct wined3d_gl_info *  gl_info,
const unsigned int *  map,
const struct wined3d_shader_signature *  input_signature,
const struct wined3d_shader_reg_maps *  reg_maps_in,
const struct wined3d_shader_signature *  output_signature,
const struct wined3d_shader_reg_maps *  reg_maps_out 
)
static

Definition at line 7090 of file glsl_shader.c.

7096{
7097 struct wined3d_string_buffer *destination = string_buffer_get(&priv->string_buffers);
7098 const char *out_array_name = shader_glsl_shader_output_name(gl_info);
7100 unsigned int in_count = vec4_varyings(3, gl_info);
7101 unsigned int max_varyings = needs_legacy_glsl_syntax(gl_info) ? in_count + 2 : in_count;
7102 unsigned int in_idx;
7103 DWORD *set = NULL;
7104 unsigned int i, j;
7105 char reg_mask[6];
7106
7107 set = calloc(max_varyings, sizeof(*set));
7108
7109 for (i = 0; i < input_signature->element_count; ++i)
7110 {
7111 const struct wined3d_shader_signature_element *input = &input_signature->elements[i];
7112
7113 if (!(reg_maps_in->input_registers & (1u << input->register_idx)))
7114 continue;
7115
7116 in_idx = map[input->register_idx];
7117 /* Declared, but not read register */
7118 if (in_idx == ~0u)
7119 continue;
7120 if (in_idx >= max_varyings)
7121 {
7122 FIXME("More input varyings declared than supported, expect issues.\n");
7123 continue;
7124 }
7125
7126 if (in_idx == in_count)
7127 string_buffer_sprintf(destination, "gl_FrontColor");
7128 else if (in_idx == in_count + 1)
7129 string_buffer_sprintf(destination, "gl_FrontSecondaryColor");
7130 else
7131 string_buffer_sprintf(destination, "%s[%u]", out_array_name, in_idx);
7132
7133 if (!set[in_idx])
7134 set[in_idx] = ~0u;
7135
7136 for (j = 0; j < output_signature->element_count; ++j)
7137 {
7138 const struct wined3d_shader_signature_element *output = &output_signature->elements[j];
7139 DWORD mask;
7140
7141 if (!(reg_maps_out->output_registers & (1u << output->register_idx))
7142 || input->semantic_idx != output->semantic_idx
7143 || strcmp(input->semantic_name, output->semantic_name)
7144 || !(mask = input->mask & output->mask))
7145 continue;
7146
7147 if (set[in_idx] == ~0u)
7148 set[in_idx] = 0;
7149 set[in_idx] |= mask & reg_maps_out->u.output_registers_mask[output->register_idx];
7151
7152 shader_addline(buffer, "%s%s = outputs[%u]%s;\n",
7153 destination->buffer, reg_mask, output->register_idx, reg_mask);
7154 }
7155 }
7156
7157 for (i = 0; i < max_varyings; ++i)
7158 {
7159 unsigned int size;
7160
7161 if (!set[i] || set[i] == WINED3DSP_WRITEMASK_ALL)
7162 continue;
7163
7164 if (set[i] == ~0u)
7165 set[i] = 0;
7166
7167 size = 0;
7168 if (!(set[i] & WINED3DSP_WRITEMASK_0))
7169 reg_mask[size++] = 'x';
7170 if (!(set[i] & WINED3DSP_WRITEMASK_1))
7171 reg_mask[size++] = 'y';
7172 if (!(set[i] & WINED3DSP_WRITEMASK_2))
7173 reg_mask[size++] = 'z';
7174 if (!(set[i] & WINED3DSP_WRITEMASK_3))
7175 reg_mask[size++] = 'w';
7176 reg_mask[size] = '\0';
7177
7178 if (i == in_count)
7179 string_buffer_sprintf(destination, "gl_FrontColor");
7180 else if (i == in_count + 1)
7181 string_buffer_sprintf(destination, "gl_FrontSecondaryColor");
7182 else
7183 string_buffer_sprintf(destination, "%s[%u]", out_array_name, i);
7184
7185 if (size == 1)
7186 shader_addline(buffer, "%s.%s = 0.0;\n", destination->buffer, reg_mask);
7187 else
7188 shader_addline(buffer, "%s.%s = vec%u(0.0);\n", destination->buffer, reg_mask, size);
7189 }
7190
7191 free(set);
7192 string_buffer_release(&priv->string_buffers, destination);
7193}
Definition: _set.h:50
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
static const char * shader_glsl_shader_output_name(const struct wined3d_gl_info *gl_info)
Definition: glsl_shader.c:2153
BYTE output_registers_mask[MAX_REG_OUTPUT]

Referenced by shader_glsl_setup_sm3_rasterizer_input().

◆ shader_glsl_sgn()

static void shader_glsl_sgn ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5023 of file glsl_shader.c.

5024{
5025 struct glsl_src_param src0_param;
5026 DWORD write_mask;
5027
5028 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
5029 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
5030
5031 shader_addline(ins->ctx->buffer, "sign(%s));\n", src0_param.param_str);
5032}

◆ shader_glsl_shader_compile()

static uint64_t shader_glsl_shader_compile ( struct wined3d_context *  context,
const struct wined3d_shader_desc *  shader_desc,
enum wined3d_shader_type  shader_type 
)
static

Definition at line 11686 of file glsl_shader.c.

11688{
11689 ERR("Not implemented.\n");
11690 return 0;
11691}

◆ shader_glsl_shader_input_name()

static const char * shader_glsl_shader_input_name ( const struct wined3d_gl_info *  gl_info)
static

Definition at line 2148 of file glsl_shader.c.

2149{
2150 return shader_glsl_use_interface_blocks(gl_info) ? "shader_in.reg" : "ps_link";
2151}

Referenced by shader_glsl_input_pack().

◆ shader_glsl_shader_output_name()

static const char * shader_glsl_shader_output_name ( const struct wined3d_gl_info *  gl_info)
static

Definition at line 2153 of file glsl_shader.c.

2154{
2155 return shader_glsl_use_interface_blocks(gl_info) ? "shader_out.reg" : "ps_link";
2156}

Referenced by shader_glsl_setup_vs3_output().

◆ shader_glsl_sincos()

static void shader_glsl_sincos ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_SINCOS instruction in GLSL: VS 2.0 requires that specific cosine and sine constants be passed to this instruction so the hardware can handle it. But, these functions are built-in for GLSL, so we can just ignore the last 2 params.

dst.x = cos(src0.?) dst.y = sin(src0.?) dst.z = dst.z dst.w = dst.w

Definition at line 4952 of file glsl_shader.c.

4953{
4954 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4955 struct glsl_src_param src0_param;
4956 DWORD write_mask;
4957
4958 if (ins->ctx->reg_maps->shader_version.major < 4)
4959 {
4960 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
4961
4962 write_mask = shader_glsl_append_dst(buffer, ins);
4963 switch (write_mask)
4964 {
4966 shader_addline(buffer, "cos(%s));\n", src0_param.param_str);
4967 break;
4968
4970 shader_addline(buffer, "sin(%s));\n", src0_param.param_str);
4971 break;
4972
4974 shader_addline(buffer, "vec2(cos(%s), sin(%s)));\n",
4975 src0_param.param_str, src0_param.param_str);
4976 break;
4977
4978 default:
4979 ERR("Write mask should be .x, .y or .xy\n");
4980 break;
4981 }
4982
4983 return;
4984 }
4985
4986 if (ins->dst[0].reg.type != WINED3DSPR_NULL)
4987 {
4988
4989 if (ins->dst[1].reg.type != WINED3DSPR_NULL)
4990 {
4991 char dst_mask[6];
4992
4993 write_mask = shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
4994 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
4995 shader_addline(buffer, "tmp0%s = sin(%s);\n", dst_mask, src0_param.param_str);
4996
4997 write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], 1, ins->dst[1].reg.data_type);
4998 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
4999 shader_addline(buffer, "cos(%s));\n", src0_param.param_str);
5000
5001 shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, ins->dst[0].reg.data_type);
5002 shader_addline(buffer, "tmp0%s);\n", dst_mask);
5003 }
5004 else
5005 {
5006 write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, ins->dst[0].reg.data_type);
5007 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
5008 shader_addline(buffer, "sin(%s));\n", src0_param.param_str);
5009 }
5010 }
5011 else if (ins->dst[1].reg.type != WINED3DSPR_NULL)
5012 {
5013 write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], 1, ins->dst[1].reg.data_type);
5014 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
5015 shader_addline(buffer, "cos(%s));\n", src0_param.param_str);
5016 }
5017}

◆ shader_glsl_sprintf_cast()

static void shader_glsl_sprintf_cast ( struct wined3d_string_buffer *  dst_param,
const char *  src_param,
enum wined3d_data_type  dst_data_type,
enum wined3d_data_type  src_data_type,
unsigned int  size 
)
static

Definition at line 3343 of file glsl_shader.c.

3345{
3346 if (dst_data_type == WINED3D_DATA_UNORM || dst_data_type == WINED3D_DATA_SNORM)
3347 dst_data_type = WINED3D_DATA_FLOAT;
3348 if (src_data_type == WINED3D_DATA_UNORM || src_data_type == WINED3D_DATA_SNORM)
3349 src_data_type = WINED3D_DATA_FLOAT;
3350
3351 if (dst_data_type == src_data_type)
3352 {
3353 string_buffer_sprintf(dst_param, "%s", src_param);
3354 return;
3355 }
3356
3357 if (src_data_type == WINED3D_DATA_FLOAT)
3358 {
3359 switch (dst_data_type)
3360 {
3361 case WINED3D_DATA_INT:
3362 string_buffer_sprintf(dst_param, "floatBitsToInt(%s)", src_param);
3363 return;
3366 case WINED3D_DATA_UINT:
3367 string_buffer_sprintf(dst_param, "floatBitsToUint(%s)", src_param);
3368 return;
3369 default:
3370 break;
3371 }
3372 }
3373
3374 if (src_data_type == WINED3D_DATA_UINT && dst_data_type == WINED3D_DATA_FLOAT)
3375 {
3376 string_buffer_sprintf(dst_param, "uintBitsToFloat(%s)", src_param);
3377 return;
3378 }
3379
3380 if (src_data_type == WINED3D_DATA_INT)
3381 {
3382 switch (dst_data_type)
3383 {
3384 case WINED3D_DATA_FLOAT:
3385 string_buffer_sprintf(dst_param, "intBitsToFloat(%s)", src_param);
3386 return;
3387 case WINED3D_DATA_UINT:
3388 if (size == 1)
3389 string_buffer_sprintf(dst_param, "uint(%s)", src_param);
3390 else
3391 string_buffer_sprintf(dst_param, "uvec%u(%s)", size, src_param);
3392 return;
3393 default:
3394 break;
3395 }
3396 }
3397
3398 FIXME("Unhandled cast from %#x to %#x.\n", src_data_type, dst_data_type);
3399 string_buffer_sprintf(dst_param, "%s", src_param);
3400}

Referenced by shader_glsl_add_src_param_ext(), and shader_glsl_generate_color_output().

◆ shader_glsl_store_raw_structured()

static void shader_glsl_store_raw_structured ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5870 of file glsl_shader.c.

5871{
5872 const char *prefix = shader_glsl_get_prefix(ins->ctx->reg_maps->shader_version.type);
5873 const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps;
5874 struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
5875 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
5876 struct glsl_src_param structure_idx, offset, data;
5877 unsigned int i, resource_idx, stride, src_idx = 0;
5879 DWORD write_mask;
5880 BOOL is_tgsm;
5881
5882 resource_idx = ins->dst[0].reg.idx[0].offset;
5883 is_tgsm = ins->dst[0].reg.type == WINED3DSPR_GROUPSHAREDMEM;
5884 if (is_tgsm)
5885 {
5886 if (resource_idx >= reg_maps->tgsm_count)
5887 {
5888 ERR("Invalid TGSM index %u.\n", resource_idx);
5889 return;
5890 }
5891 stride = reg_maps->tgsm[resource_idx].stride;
5892 }
5893 else
5894 {
5895 if (resource_idx >= ARRAY_SIZE(reg_maps->uav_resource_info))
5896 {
5897 ERR("Invalid UAV index %u.\n", resource_idx);
5898 return;
5899 }
5900 stride = reg_maps->uav_resource_info[resource_idx].stride;
5901 }
5902
5905 {
5906 shader_glsl_add_src_param(ins, &ins->src[src_idx++], WINED3DSP_WRITEMASK_0, &structure_idx);
5907 shader_addline(address, "%s * %u + ", structure_idx.param_str, stride);
5908 }
5910 shader_addline(address, "%s / 4", offset.param_str);
5911
5912 for (i = 0; i < 4; ++i)
5913 {
5914 if (!(write_mask = ins->dst[0].write_mask & (WINED3DSP_WRITEMASK_0 << i)))
5915 continue;
5916
5917 shader_glsl_add_src_param(ins, &ins->src[src_idx], write_mask, &data);
5918
5919 if (is_tgsm)
5920 shader_addline(buffer, "%s_g%u[%s + %u] = %s;\n",
5921 prefix, resource_idx, address->buffer, i, data.param_str);
5922 else
5923 shader_addline(buffer, "imageStore(%s_image%u, %s + %u, uvec4(%s, 0, 0, 0));\n",
5924 prefix, resource_idx, address->buffer, i, data.param_str);
5925 }
5926
5928}
@ WINED3DSIH_STORE_STRUCTURED

◆ shader_glsl_store_uav()

static void shader_glsl_store_uav ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5838 of file glsl_shader.c.

5839{
5840 const struct wined3d_shader_reg_maps *reg_maps = ins->ctx->reg_maps;
5841 const struct wined3d_shader_version *version = &reg_maps->shader_version;
5842 struct glsl_src_param image_coord_param, image_data_param;
5843 enum wined3d_shader_resource_type resource_type;
5845 unsigned int uav_idx;
5846 DWORD coord_mask;
5847
5848 uav_idx = ins->dst[0].reg.idx[0].offset;
5849 if (uav_idx >= ARRAY_SIZE(reg_maps->uav_resource_info))
5850 {
5851 ERR("Invalid UAV index %u.\n", uav_idx);
5852 return;
5853 }
5854 resource_type = reg_maps->uav_resource_info[uav_idx].type;
5855 if (resource_type >= ARRAY_SIZE(resource_type_info))
5856 {
5857 ERR("Unexpected resource type %#x.\n", resource_type);
5858 return;
5859 }
5860 data_type = reg_maps->uav_resource_info[uav_idx].data_type;
5861 coord_mask = wined3d_mask_from_size(resource_type_info[resource_type].coord_size);
5862
5863 shader_glsl_add_src_param(ins, &ins->src[0], coord_mask, &image_coord_param);
5864 shader_glsl_add_src_param_ext(ins->ctx, &ins->src[1], WINED3DSP_WRITEMASK_ALL, &image_data_param, data_type);
5865 shader_addline(ins->ctx->buffer, "imageStore(%s_image%u, %s, %s);\n",
5866 shader_glsl_get_prefix(version->type), uav_idx,
5867 image_coord_param.param_str, image_data_param.param_str);
5868}

◆ shader_glsl_swapc()

static void shader_glsl_swapc ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4583 of file glsl_shader.c.

4584{
4585 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4586 struct wined3d_shader_dst_param dst[2];
4587 struct glsl_src_param src[3];
4588 unsigned int i, j, k;
4589 char mask_char[6];
4590 DWORD write_mask;
4591 BOOL tmp_dst[2];
4592
4593 for (i = 0; i < ins->dst_count; ++i)
4594 {
4595 tmp_dst[i] = FALSE;
4596 for (j = 0; j < ins->src_count; ++j)
4597 {
4598 if (ins->dst[i].reg.idx[0].offset == ins->src[j].reg.idx[0].offset
4599 && ins->dst[i].reg.type == ins->src[j].reg.type)
4600 tmp_dst[i] = TRUE;
4601 }
4602 }
4603
4604 dst[0] = ins->dst[0];
4605 dst[1] = ins->dst[1];
4606 for (i = 0; i < 4; ++i)
4607 {
4608 for (j = 0; j < ARRAY_SIZE(dst); ++j)
4609 {
4610 dst[j].write_mask = ins->dst[j].write_mask & (WINED3DSP_WRITEMASK_0 << i);
4611 if (tmp_dst[j] && (write_mask = shader_glsl_get_write_mask(&dst[j], mask_char)))
4612 shader_addline(buffer, "tmp%u%s = (", j, mask_char);
4613 else if (!(write_mask = shader_glsl_append_dst_ext(buffer, ins, &dst[j], j, dst[j].reg.data_type)))
4614 continue;
4615
4616 for (k = 0; k < ARRAY_SIZE(src); ++k)
4617 shader_glsl_add_src_param(ins, &ins->src[k], write_mask, &src[k]);
4618
4619 shader_addline(buffer, "%sbool(%s) ? %s : %s);\n", !j ? "!" : "",
4620 src[0].param_str, src[1].param_str, src[2].param_str);
4621 }
4622 }
4623
4624 for (i = 0; i < ARRAY_SIZE(tmp_dst); ++i)
4625 {
4626 if (tmp_dst[i])
4627 {
4628 shader_glsl_get_write_mask(&ins->dst[i], mask_char);
4629 shader_glsl_append_dst_ext(buffer, ins, &ins->dst[i], i, ins->dst[i].reg.data_type);
4630 shader_addline(buffer, "tmp%u%s);\n", i, mask_char);
4631 }
4632 }
4633}

◆ shader_glsl_switch()

static void shader_glsl_switch ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5178 of file glsl_shader.c.

5179{
5180 struct glsl_src_param src0_param;
5181
5182 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_0, &src0_param);
5183 shader_addline(ins->ctx->buffer, "switch (%s)\n{\n", src0_param.param_str);
5184}

◆ shader_glsl_swizzle_get_component()

static unsigned int shader_glsl_swizzle_get_component ( DWORD  swizzle,
unsigned int  component_idx 
)
static

Definition at line 3310 of file glsl_shader.c.

3312{
3313 /* swizzle bits fields: wwzzyyxx */
3314 return (swizzle >> (2 * component_idx)) & 0x3;
3315}

Referenced by shader_glsl_conditional_move(), shader_glsl_gather4(), shader_glsl_ld_raw_structured(), and shader_glsl_swizzle_to_str().

◆ shader_glsl_swizzle_to_str()

static void shader_glsl_swizzle_to_str ( DWORD  swizzle,
BOOL  fixup,
DWORD  mask,
char *  str 
)
static

Definition at line 3317 of file glsl_shader.c.

3318{
3319 /* For registers of type WINED3DDECLTYPE_D3DCOLOR, data is stored as "bgra",
3320 * but addressed as "rgba". To fix this we need to swap the register's x
3321 * and z components. */
3322 const char *swizzle_chars = fixup ? "zyxw" : "xyzw";
3323 unsigned int i;
3324
3325 *str++ = '.';
3326 for (i = 0; i < 4; ++i)
3327 {
3328 if (mask & (WINED3DSP_WRITEMASK_0 << i))
3329 *str++ = swizzle_chars[shader_glsl_swizzle_get_component(swizzle, i)];
3330 }
3331 *str = '\0';
3332}

Referenced by PRINTF_ATTR(), shader_glsl_gather4(), shader_glsl_gen_sample_c_lz_emulation(), and shader_glsl_get_swizzle().

◆ shader_glsl_sync()

static void shader_glsl_sync ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5930 of file glsl_shader.c.

5931{
5932 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
5933 unsigned int sync_flags = ins->flags;
5934
5935 if (sync_flags & WINED3DSSF_THREAD_GROUP)
5936 {
5937 shader_addline(buffer, "barrier();\n");
5939 }
5940
5941 if (sync_flags & WINED3DSSF_GROUP_SHARED_MEMORY)
5942 {
5943 shader_addline(buffer, "memoryBarrierShared();\n");
5944 sync_flags &= ~WINED3DSSF_GROUP_SHARED_MEMORY;
5945 }
5946
5947 if (sync_flags & WINED3DSSF_GLOBAL_UAV)
5948 {
5949 shader_addline(buffer, "memoryBarrier();\n");
5950 sync_flags &= ~WINED3DSSF_GLOBAL_UAV;
5951 }
5952
5953 if (sync_flags)
5954 FIXME("Unhandled sync flags %#x.\n", sync_flags);
5955}
@ WINED3DSSF_THREAD_GROUP
@ WINED3DSSF_GROUP_SHARED_MEMORY
@ WINED3DSSF_GLOBAL_UAV

◆ shader_glsl_tex()

static void shader_glsl_tex ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5336 of file glsl_shader.c.

5337{
5338 DWORD shader_version = WINED3D_SHADER_VERSION(ins->ctx->reg_maps->shader_version.major,
5339 ins->ctx->reg_maps->shader_version.minor);
5340 struct glsl_sample_function sample_function;
5341 DWORD sample_flags = 0;
5342 unsigned int resource_idx;
5343 DWORD mask = 0, swizzle;
5344 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
5345 enum wined3d_shader_resource_type resource_type;
5346
5347 /* 1.0-1.4: Use destination register as sampler source.
5348 * 2.0+: Use provided sampler source. */
5349 if (shader_version < WINED3D_SHADER_VERSION(2,0))
5350 resource_idx = ins->dst[0].reg.idx[0].offset;
5351 else
5352 resource_idx = ins->src[1].reg.idx[0].offset;
5353
5354 resource_type = ins->ctx->reg_maps->shader_version.type == WINED3D_SHADER_TYPE_PIXEL
5355 ? pixelshader_get_resource_type(ins->ctx->reg_maps, resource_idx, priv->cur_ps_args->tex_types)
5356 : ins->ctx->reg_maps->resource_info[resource_idx].type;
5357
5358 if (shader_version < WINED3D_SHADER_VERSION(1,4))
5359 {
5360 DWORD flags = (priv->cur_ps_args->tex_transform >> resource_idx * WINED3D_PSARGS_TEXTRANSFORM_SHIFT)
5362
5363 /* Projected cube textures don't make a lot of sense, the resulting coordinates stay the same. */
5365 {
5366 sample_flags |= WINED3D_GLSL_SAMPLE_PROJECTED;
5368 {
5370 FIXME("WINED3D_TTFF_PROJECTED with WINED3D_TTFF_COUNT1?\n");
5371 break;
5374 break;
5377 break;
5381 break;
5382 }
5383 }
5384 }
5385 else if (shader_version < WINED3D_SHADER_VERSION(2,0))
5386 {
5387 enum wined3d_shader_src_modifier src_mod = ins->src[0].modifiers;
5388
5389 if (src_mod == WINED3DSPSM_DZ) {
5390 sample_flags |= WINED3D_GLSL_SAMPLE_PROJECTED;
5392 } else if (src_mod == WINED3DSPSM_DW) {
5393 sample_flags |= WINED3D_GLSL_SAMPLE_PROJECTED;
5395 }
5396 }
5397 else
5398 {
5399 if ((ins->flags & WINED3DSI_TEXLD_PROJECT)
5400 && resource_type != WINED3D_SHADER_RESOURCE_TEXTURE_CUBE)
5401 {
5402 /* ps 2.0 texldp instruction always divides by the fourth component. */
5403 sample_flags |= WINED3D_GLSL_SAMPLE_PROJECTED;
5405 }
5406 }
5407
5408 shader_glsl_get_sample_function(ins->ctx, resource_idx, resource_idx, sample_flags, &sample_function);
5409 mask |= sample_function.coord_mask;
5410 sample_function.coord_mask = mask;
5411
5412 if (shader_version < WINED3D_SHADER_VERSION(2,0)) swizzle = WINED3DSP_NOSWIZZLE;
5413 else swizzle = ins->src[1].swizzle;
5414
5415 /* 1.0-1.3: Use destination register as coordinate source.
5416 1.4+: Use provided coordinate source register. */
5417 if (shader_version < WINED3D_SHADER_VERSION(1,4))
5418 {
5419 char coord_mask[6];
5421 shader_glsl_gen_sample_code(ins, resource_idx, &sample_function, swizzle, NULL, NULL, NULL, NULL,
5422 "T%u%s", resource_idx, coord_mask);
5423 }
5424 else
5425 {
5426 struct glsl_src_param coord_param;
5427 shader_glsl_add_src_param(ins, &ins->src[0], mask, &coord_param);
5428 if (ins->flags & WINED3DSI_TEXLD_BIAS)
5429 {
5430 struct glsl_src_param bias;
5432 shader_glsl_gen_sample_code(ins, resource_idx, &sample_function, swizzle, NULL, NULL, bias.param_str,
5433 NULL, "%s", coord_param.param_str);
5434 } else {
5435 shader_glsl_gen_sample_code(ins, resource_idx, &sample_function, swizzle, NULL, NULL, NULL, NULL,
5436 "%s", coord_param.param_str);
5437 }
5438 }
5439 shader_glsl_release_sample_function(ins->ctx, &sample_function);
5440}
@ WINED3D_TTFF_COUNT2
Definition: wined3d.h:620
@ WINED3D_TTFF_COUNT4
Definition: wined3d.h:622
@ WINED3D_TTFF_DISABLE
Definition: wined3d.h:618
@ WINED3D_TTFF_COUNT3
Definition: wined3d.h:621
@ WINED3D_TTFF_COUNT1
Definition: wined3d.h:619
#define WINED3DSI_TEXLD_BIAS
#define WINED3D_PSARGS_PROJECTED
wined3d_shader_src_modifier
#define WINED3D_PSARGS_TEXTRANSFORM_SHIFT
#define WINED3D_PSARGS_TEXTRANSFORM_MASK
#define WINED3DSI_TEXLD_PROJECT

Referenced by shader_glsl_texldd().

◆ shader_glsl_texbem()

static void shader_glsl_texbem ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXBEM instruction in GLSL. Apply a fake bump map transform. texbem is pshader <= 1.3 only, this saves a few version checks

Definition at line 6745 of file glsl_shader.c.

6746{
6747 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
6748 struct glsl_sample_function sample_function;
6749 struct glsl_src_param coord_param;
6750 unsigned int sampler_idx;
6751 DWORD mask;
6752 DWORD flags;
6753 char coord_mask[6];
6754
6755 sampler_idx = ins->dst[0].reg.idx[0].offset;
6756 flags = (priv->cur_ps_args->tex_transform >> sampler_idx * WINED3D_PSARGS_TEXTRANSFORM_SHIFT)
6758
6759 /* Dependent read, not valid with conditional NP2 */
6760 shader_glsl_get_sample_function(ins->ctx, sampler_idx, sampler_idx, 0, &sample_function);
6761 mask = sample_function.coord_mask;
6762
6764
6765 /* With projected textures, texbem only divides the static texture coord,
6766 * not the displacement, so we can't let GL handle this. */
6768 {
6769 DWORD div_mask=0;
6770 char coord_div_mask[3];
6772 {
6774 FIXME("WINED3D_TTFF_PROJECTED with WINED3D_TTFF_COUNT1?\n");
6775 break;
6777 div_mask = WINED3DSP_WRITEMASK_1;
6778 break;
6780 div_mask = WINED3DSP_WRITEMASK_2;
6781 break;
6784 div_mask = WINED3DSP_WRITEMASK_3;
6785 break;
6786 }
6787 shader_glsl_write_mask_to_str(div_mask, coord_div_mask);
6788 shader_addline(ins->ctx->buffer, "T%u%s /= T%u%s;\n", sampler_idx, coord_mask, sampler_idx, coord_div_mask);
6789 }
6790
6792
6793 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, NULL,
6794 "T%u%s + vec4(bumpenv_mat%u * %s, 0.0, 0.0)%s", sampler_idx, coord_mask, sampler_idx,
6795 coord_param.param_str, coord_mask);
6796
6797 if (ins->handler_idx == WINED3DSIH_TEXBEML)
6798 {
6799 struct glsl_src_param luminance_param;
6800 struct glsl_dst_param dst_param;
6801
6802 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_2, &luminance_param);
6803 shader_glsl_add_dst_param(ins, &ins->dst[0], &dst_param);
6804
6805 shader_addline(ins->ctx->buffer, "%s%s *= (%s * bumpenv_lum_scale%u + bumpenv_lum_offset%u);\n",
6806 dst_param.reg_name, dst_param.mask_str,
6807 luminance_param.param_str, sampler_idx, sampler_idx);
6808 }
6809 shader_glsl_release_sample_function(ins->ctx, &sample_function);
6810}
@ WINED3DSIH_TEXBEML

◆ shader_glsl_texcoord()

static void shader_glsl_texcoord ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 6443 of file glsl_shader.c.

6444{
6445 /* FIXME: Make this work for more than just 2D textures */
6446 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
6447 DWORD write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
6448
6449 if (!(ins->ctx->reg_maps->shader_version.major == 1 && ins->ctx->reg_maps->shader_version.minor == 4))
6450 {
6451 char dst_mask[6];
6452
6453 shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
6454 shader_addline(buffer, "clamp(ffp_texcoord[%u], 0.0, 1.0)%s);\n",
6455 ins->dst[0].reg.idx[0].offset, dst_mask);
6456 }
6457 else
6458 {
6459 enum wined3d_shader_src_modifier src_mod = ins->src[0].modifiers;
6460 unsigned int reg = ins->src[0].reg.idx[0].offset;
6461 char dst_swizzle[6];
6462
6463 shader_glsl_get_swizzle(&ins->src[0], FALSE, write_mask, dst_swizzle);
6464
6465 if (src_mod == WINED3DSPSM_DZ || src_mod == WINED3DSPSM_DW)
6466 {
6467 unsigned int mask_size = shader_glsl_get_write_mask_size(write_mask);
6468 struct glsl_src_param div_param;
6469 DWORD src_writemask = src_mod == WINED3DSPSM_DZ ? WINED3DSP_WRITEMASK_2 : WINED3DSP_WRITEMASK_3;
6470
6471 shader_glsl_add_src_param(ins, &ins->src[0], src_writemask, &div_param);
6472
6473 if (mask_size > 1)
6474 shader_addline(buffer, "ffp_texcoord[%u]%s / vec%d(%s));\n", reg, dst_swizzle, mask_size, div_param.param_str);
6475 else
6476 shader_addline(buffer, "ffp_texcoord[%u]%s / %s);\n", reg, dst_swizzle, div_param.param_str);
6477 }
6478 else
6479 {
6480 shader_addline(buffer, "ffp_texcoord[%u]%s);\n", reg, dst_swizzle);
6481 }
6482 }
6483}

◆ shader_glsl_texdepth()

static void shader_glsl_texdepth ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXDEPTH instruction in GLSL: Calculate the depth as dst.x / dst.y

Definition at line 6553 of file glsl_shader.c.

6554{
6555 struct glsl_dst_param dst_param;
6556
6557 shader_glsl_add_dst_param(ins, &ins->dst[0], &dst_param);
6558
6559 /* Tests show that texdepth never returns anything below 0.0, and that r5.y is clamped to 1.0.
6560 * Negative input is accepted, -0.25 / -0.5 returns 0.5. GL should clamp gl_FragDepth to [0;1], but
6561 * this doesn't always work, so clamp the results manually. Whether or not the x value is clamped at 1
6562 * too is irrelevant, since if x = 0, any y value < 1.0 (and > 1.0 is not allowed) results in a result
6563 * >= 1.0 or < 0.0
6564 */
6565 shader_addline(ins->ctx->buffer, "gl_FragDepth = clamp((%s.x / min(%s.y, 1.0)), 0.0, 1.0);\n",
6566 dst_param.reg_name, dst_param.reg_name);
6567}

◆ shader_glsl_texdp3()

static void shader_glsl_texdp3 ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXDP3 instruction in GLSL: Take a 3-component dot product of the TexCoord[dstreg] and src.

Definition at line 6532 of file glsl_shader.c.

6533{
6535 unsigned int dstreg = ins->dst[0].reg.idx[0].offset;
6536 struct glsl_src_param src0_param;
6537 DWORD dst_mask;
6538 unsigned int mask_size;
6539
6540 dst_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
6541 mask_size = shader_glsl_get_write_mask_size(dst_mask);
6542 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
6543
6544 if (mask_size > 1) {
6545 shader_addline(ins->ctx->buffer, "vec%d(dot(T%u.xyz, %s)));\n", mask_size, dstreg, src0_param.param_str);
6546 } else {
6547 shader_addline(ins->ctx->buffer, "dot(T%u.xyz, %s));\n", dstreg, src0_param.param_str);
6548 }
6549}

◆ shader_glsl_texdp3tex()

static void shader_glsl_texdp3tex ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXDP3TEX instruction in GLSL: Take a 3-component dot product of the TexCoord[dstreg] and src, then perform a 1D texture lookup from stage dstregnum, place into dst.

Definition at line 6488 of file glsl_shader.c.

6489{
6491 unsigned int sampler_idx = ins->dst[0].reg.idx[0].offset;
6492 struct glsl_sample_function sample_function;
6493 struct glsl_src_param src0_param;
6494 UINT mask_size;
6495
6496 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
6497
6498 /* Do I have to take care about the projected bit? I don't think so, since the dp3 returns only one
6499 * scalar, and projected sampling would require 4.
6500 *
6501 * It is a dependent read - not valid with conditional NP2 textures
6502 */
6503 shader_glsl_get_sample_function(ins->ctx, sampler_idx, sampler_idx, 0, &sample_function);
6504 mask_size = shader_glsl_get_write_mask_size(sample_function.coord_mask);
6505
6506 switch(mask_size)
6507 {
6508 case 1:
6509 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
6510 NULL, "dot(ffp_texcoord[%u].xyz, %s)", sampler_idx, src0_param.param_str);
6511 break;
6512
6513 case 2:
6514 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
6515 NULL, "vec2(dot(ffp_texcoord[%u].xyz, %s), 0.0)", sampler_idx, src0_param.param_str);
6516 break;
6517
6518 case 3:
6519 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL,
6520 NULL, "vec3(dot(ffp_texcoord[%u].xyz, %s), 0.0, 0.0)", sampler_idx, src0_param.param_str);
6521 break;
6522
6523 default:
6524 FIXME("Unexpected mask size %u\n", mask_size);
6525 break;
6526 }
6527 shader_glsl_release_sample_function(ins->ctx, &sample_function);
6528}

◆ shader_glsl_texkill()

static void shader_glsl_texkill ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXKILL instruction in GLSL. If any of the first 3 components are < 0, discard this pixel

Definition at line 6884 of file glsl_shader.c.

6885{
6886 if (ins->ctx->reg_maps->shader_version.major >= 4)
6887 {
6889 shader_addline(ins->ctx->buffer, " discard;\n");
6890 }
6891 else
6892 {
6893 struct glsl_dst_param dst_param;
6894
6895 /* The argument is a destination parameter, and no writemasks are allowed */
6896 shader_glsl_add_dst_param(ins, &ins->dst[0], &dst_param);
6897
6898 /* 2.0 shaders compare all 4 components in texkill. */
6899 if (ins->ctx->reg_maps->shader_version.major >= 2)
6900 shader_addline(ins->ctx->buffer, "if (any(lessThan(%s.xyzw, vec4(0.0)))) discard;\n", dst_param.reg_name);
6901 /* 1.x shaders only compare the first 3 components, probably due to
6902 * the nature of the texkill instruction as a tex* instruction, and
6903 * phase, which kills all .w components. Even if all 4 components are
6904 * defined, only the first 3 are used. */
6905 else
6906 shader_addline(ins->ctx->buffer, "if (any(lessThan(%s.xyz, vec3(0.0)))) discard;\n", dst_param.reg_name);
6907 }
6908}

◆ shader_glsl_texldd()

static void shader_glsl_texldd ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5442 of file glsl_shader.c.

5443{
5444 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
5445 const struct wined3d_gl_info *gl_info = priv->gl_info;
5446 struct glsl_src_param coord_param, dx_param, dy_param;
5447 struct glsl_sample_function sample_function;
5448 DWORD sampler_idx;
5449 DWORD swizzle = ins->src[1].swizzle;
5450
5452 {
5453 FIXME("texldd used, but not supported by hardware. Falling back to regular tex.\n");
5454 shader_glsl_tex(ins);
5455 return;
5456 }
5457
5458 sampler_idx = ins->src[1].reg.idx[0].offset;
5459
5460 shader_glsl_get_sample_function(ins->ctx, sampler_idx, sampler_idx, WINED3D_GLSL_SAMPLE_GRAD, &sample_function);
5461 shader_glsl_add_src_param(ins, &ins->src[0], sample_function.coord_mask, &coord_param);
5462 shader_glsl_add_src_param(ins, &ins->src[2], sample_function.deriv_mask, &dx_param);
5463 shader_glsl_add_src_param(ins, &ins->src[3], sample_function.deriv_mask, &dy_param);
5464
5465 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, dx_param.param_str, dy_param.param_str,
5466 NULL, NULL, "%s", coord_param.param_str);
5467 shader_glsl_release_sample_function(ins->ctx, &sample_function);
5468}
static void shader_glsl_tex(const struct wined3d_shader_instruction *ins)
Definition: glsl_shader.c:5336

◆ shader_glsl_texldl()

static void shader_glsl_texldl ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5470 of file glsl_shader.c.

5471{
5472 const struct wined3d_shader_version *shader_version = &ins->ctx->reg_maps->shader_version;
5473 const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
5474 const struct wined3d_gl_info *gl_info = priv->gl_info;
5475 struct glsl_src_param coord_param, lod_param;
5476 struct glsl_sample_function sample_function;
5477 DWORD swizzle = ins->src[1].swizzle;
5478 DWORD sampler_idx;
5479
5480 sampler_idx = ins->src[1].reg.idx[0].offset;
5481
5482 shader_glsl_get_sample_function(ins->ctx, sampler_idx, sampler_idx, WINED3D_GLSL_SAMPLE_LOD, &sample_function);
5483 shader_glsl_add_src_param(ins, &ins->src[0], sample_function.coord_mask, &coord_param);
5484
5485 shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &lod_param);
5486
5487 if (shader_version->type == WINED3D_SHADER_TYPE_PIXEL && !shader_glsl_has_core_grad(gl_info)
5488 && !gl_info->supported[ARB_SHADER_TEXTURE_LOD])
5489 {
5490 /* Plain GLSL only supports Lod sampling functions in vertex shaders.
5491 * However, the NVIDIA drivers allow them in fragment shaders as well,
5492 * even without the appropriate extension. */
5493 WARN("Using %s in fragment shader.\n", sample_function.name->buffer);
5494 }
5495 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, swizzle, NULL, NULL, lod_param.param_str, NULL,
5496 "%s", coord_param.param_str);
5497 shader_glsl_release_sample_function(ins->ctx, &sample_function);
5498}

◆ shader_glsl_texm3x2depth()

static void shader_glsl_texm3x2depth ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXM3X2DEPTH instruction in GLSL: Last row of a 3x2 matrix multiply, use the result to calculate the depth: Calculate tmp0.y = TexCoord[dstreg] . src.xyz; (tmp0.x has already been calculated) depth = (tmp0.y == 0.0) ? 1.0 : tmp0.x / tmp0.y

Definition at line 6574 of file glsl_shader.c.

6575{
6577 unsigned int dstreg = ins->dst[0].reg.idx[0].offset;
6578 struct glsl_src_param src0_param;
6579
6580 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
6581
6582 shader_addline(ins->ctx->buffer, "tmp0.y = dot(T%u.xyz, %s);\n", dstreg, src0_param.param_str);
6583 shader_addline(ins->ctx->buffer, "gl_FragDepth = (tmp0.y == 0.0) ? 1.0 : clamp(tmp0.x / tmp0.y, 0.0, 1.0);\n");
6584}

◆ shader_glsl_texm3x2pad()

static void shader_glsl_texm3x2pad ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXM3X2PAD instruction in GLSL Calculate the 1st of a 2-row matrix multiplication.

Definition at line 6588 of file glsl_shader.c.

6589{
6591 unsigned int reg = ins->dst[0].reg.idx[0].offset;
6592 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
6593 struct glsl_src_param src0_param;
6594
6595 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
6596 shader_addline(buffer, "tmp0.x = dot(T%u.xyz, %s);\n", reg, src0_param.param_str);
6597}

◆ shader_glsl_texm3x2tex()

static void shader_glsl_texm3x2tex ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 6614 of file glsl_shader.c.

6615{
6617 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
6618 struct glsl_sample_function sample_function;
6619 unsigned int reg = ins->dst[0].reg.idx[0].offset;
6620 struct glsl_src_param src0_param;
6621
6622 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
6623 shader_addline(buffer, "tmp0.y = dot(T%u.xyz, %s);\n", reg, src0_param.param_str);
6624
6625 shader_glsl_get_sample_function(ins->ctx, reg, reg, 0, &sample_function);
6626
6627 /* Sample the texture using the calculated coordinates */
6628 shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, NULL, "tmp0.xy");
6629 shader_glsl_release_sample_function(ins->ctx, &sample_function);
6630}

◆ shader_glsl_texm3x3()

static void shader_glsl_texm3x3 ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXM3X3 instruction in GLSL Perform the 3rd row of a 3x3 matrix multiply

Definition at line 6657 of file glsl_shader.c.

6658{
6660 struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
6661 unsigned int reg = ins->dst[0].reg.idx[0].offset;
6662 struct glsl_src_param src0_param;
6663 char dst_mask[6];
6664
6665 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
6666
6667 shader_glsl_append_dst(ins->ctx->buffer, ins);
6668 shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
6669 shader_addline(ins->ctx->buffer, "vec4(tmp0.xy, dot(T%u.xyz, %s), 1.0)%s);\n", reg, src0_param.param_str, dst_mask);
6670
6671 tex_mx->current_row = 0;
6672}

◆ shader_glsl_texm3x3pad()

static void shader_glsl_texm3x3pad ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXM3X3PAD instruction in GLSL Calculate the 1st or 2nd row of a 3-row matrix multiplication.

Definition at line 6601 of file glsl_shader.c.

6602{
6604 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
6605 struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
6606 unsigned int reg = ins->dst[0].reg.idx[0].offset;
6607 struct glsl_src_param src0_param;
6608
6609 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
6610 shader_addline(buffer, "tmp0.%c = dot(T%u.xyz, %s);\n", 'x' + tex_mx->current_row, reg, src0_param.param_str);
6611 tex_mx->texcoord_w[tex_mx->current_row++] = reg;
6612}
unsigned int texcoord_w[2]

◆ shader_glsl_texm3x3spec()

static void shader_glsl_texm3x3spec ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 6676 of file glsl_shader.c.

6677{
6678 struct glsl_src_param src0_param;
6679 struct glsl_src_param src1_param;
6680 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
6681 struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
6683 struct glsl_sample_function sample_function;
6684 unsigned int reg = ins->dst[0].reg.idx[0].offset;
6685 char coord_mask[6];
6686
6687 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
6688 shader_glsl_add_src_param(ins, &ins->src[1], src_mask, &src1_param);
6689
6690 /* Perform the last matrix multiply operation */
6691 shader_addline(buffer, "tmp0.z = dot(T%u.xyz, %s);\n", reg, src0_param.param_str);
6692 /* Reflection calculation */
6693 shader_addline(buffer, "tmp0.xyz = -reflect((%s), normalize(tmp0.xyz));\n", src1_param.param_str);
6694
6695 /* Dependent read, not valid with conditional NP2 */
6696 shader_glsl_get_sample_function(ins->ctx, reg, reg, 0, &sample_function);
6697 shader_glsl_write_mask_to_str(sample_function.coord_mask, coord_mask);
6698
6699 /* Sample the texture */
6700 shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE,
6701 NULL, NULL, NULL, NULL, "tmp0%s", coord_mask);
6702 shader_glsl_release_sample_function(ins->ctx, &sample_function);
6703
6704 tex_mx->current_row = 0;
6705}

◆ shader_glsl_texm3x3tex()

static void shader_glsl_texm3x3tex ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXM3X3TEX instruction in GLSL Perform the 3rd row of a 3x3 matrix multiply, then sample the texture using the calculated coordinates

Definition at line 6634 of file glsl_shader.c.

6635{
6637 struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
6638 struct glsl_sample_function sample_function;
6639 unsigned int reg = ins->dst[0].reg.idx[0].offset;
6640 struct glsl_src_param src0_param;
6641
6642 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
6643 shader_addline(ins->ctx->buffer, "tmp0.z = dot(T%u.xyz, %s);\n", reg, src0_param.param_str);
6644
6645 /* Dependent read, not valid with conditional NP2 */
6646 shader_glsl_get_sample_function(ins->ctx, reg, reg, 0, &sample_function);
6647
6648 /* Sample the texture using the calculated coordinates */
6649 shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, NULL, "tmp0.xyz");
6650 shader_glsl_release_sample_function(ins->ctx, &sample_function);
6651
6652 tex_mx->current_row = 0;
6653}

◆ shader_glsl_texm3x3vspec()

static void shader_glsl_texm3x3vspec ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 6709 of file glsl_shader.c.

6710{
6711 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
6712 struct wined3d_shader_tex_mx *tex_mx = ins->ctx->tex_mx;
6714 struct glsl_sample_function sample_function;
6715 unsigned int reg = ins->dst[0].reg.idx[0].offset;
6716 struct glsl_src_param src0_param;
6717 char coord_mask[6];
6718
6719 shader_glsl_add_src_param(ins, &ins->src[0], src_mask, &src0_param);
6720
6721 /* Perform the last matrix multiply operation */
6722 shader_addline(buffer, "tmp0.z = dot(vec3(T%u), vec3(%s));\n", reg, src0_param.param_str);
6723
6724 /* Construct the eye-ray vector from w coordinates */
6725 shader_addline(buffer, "tmp1.xyz = normalize(vec3(ffp_texcoord[%u].w, ffp_texcoord[%u].w, ffp_texcoord[%u].w));\n",
6726 tex_mx->texcoord_w[0], tex_mx->texcoord_w[1], reg);
6727 shader_addline(buffer, "tmp0.xyz = -reflect(tmp1.xyz, normalize(tmp0.xyz));\n");
6728
6729 /* Dependent read, not valid with conditional NP2 */
6730 shader_glsl_get_sample_function(ins->ctx, reg, reg, 0, &sample_function);
6731 shader_glsl_write_mask_to_str(sample_function.coord_mask, coord_mask);
6732
6733 /* Sample the texture using the calculated coordinates */
6734 shader_glsl_gen_sample_code(ins, reg, &sample_function, WINED3DSP_NOSWIZZLE,
6735 NULL, NULL, NULL, NULL, "tmp0%s", coord_mask);
6736 shader_glsl_release_sample_function(ins->ctx, &sample_function);
6737
6738 tex_mx->current_row = 0;
6739}

◆ shader_glsl_texreg2ar()

static void shader_glsl_texreg2ar ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXREG2AR instruction in GLSL Sample 2D texture at dst using the alpha & red (wx) components of src as texture coordinates

Definition at line 6827 of file glsl_shader.c.

6828{
6829 struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
6830 DWORD sampler_idx = ins->dst[0].reg.idx[0].offset;
6831 struct glsl_sample_function sample_function;
6833
6835 shader_glsl_get_register_name(&ins->src[0].reg, ins->src[0].reg.data_type, reg_name, NULL, ins->ctx);
6836
6837 shader_glsl_get_sample_function(ins->ctx, sampler_idx, sampler_idx, 0, &sample_function);
6838 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, NULL,
6839 "%s.wx", reg_name->buffer);
6840 shader_glsl_release_sample_function(ins->ctx, &sample_function);
6841
6843}

◆ shader_glsl_texreg2gb()

static void shader_glsl_texreg2gb ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXREG2GB instruction in GLSL Sample 2D texture at dst using the green & blue (yz) components of src as texture coordinates

Definition at line 6847 of file glsl_shader.c.

6848{
6849 struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
6850 DWORD sampler_idx = ins->dst[0].reg.idx[0].offset;
6851 struct glsl_sample_function sample_function;
6853
6855 shader_glsl_get_register_name(&ins->src[0].reg, ins->src[0].reg.data_type, reg_name, NULL, ins->ctx);
6856
6857 shader_glsl_get_sample_function(ins->ctx, sampler_idx, sampler_idx, 0, &sample_function);
6858 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, NULL,
6859 "%s.yz", reg_name->buffer);
6860 shader_glsl_release_sample_function(ins->ctx, &sample_function);
6861
6863}

◆ shader_glsl_texreg2rgb()

static void shader_glsl_texreg2rgb ( const struct wined3d_shader_instruction *  ins)
static

Process the WINED3DSIO_TEXREG2RGB instruction in GLSL Sample texture at dst using the rgb (xyz) components of src as texture coordinates

Definition at line 6867 of file glsl_shader.c.

6868{
6869 DWORD sampler_idx = ins->dst[0].reg.idx[0].offset;
6870 struct glsl_sample_function sample_function;
6871 struct glsl_src_param src0_param;
6872
6873 /* Dependent read, not valid with conditional NP2 */
6874 shader_glsl_get_sample_function(ins->ctx, sampler_idx, sampler_idx, 0, &sample_function);
6875 shader_glsl_add_src_param(ins, &ins->src[0], sample_function.coord_mask, &src0_param);
6876
6877 shader_glsl_gen_sample_code(ins, sampler_idx, &sample_function, WINED3DSP_NOSWIZZLE, NULL, NULL, NULL, NULL,
6878 "%s", src0_param.param_str);
6879 shader_glsl_release_sample_function(ins->ctx, &sample_function);
6880}

◆ shader_glsl_to_float()

static void shader_glsl_to_float ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4527 of file glsl_shader.c.

4528{
4529 shader_glsl_cast(ins, "vec", "float");
4530}
static void shader_glsl_cast(const struct wined3d_shader_instruction *ins, const char *vector_constructor, const char *scalar_constructor)
Definition: glsl_shader.c:4471

◆ shader_glsl_to_int()

static void shader_glsl_to_int ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4489 of file glsl_shader.c.

4490{
4491 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4492 struct glsl_src_param src_param;
4493 unsigned int mask_size;
4494 DWORD write_mask;
4495
4496 write_mask = shader_glsl_append_dst(buffer, ins);
4497 mask_size = shader_glsl_get_write_mask_size(write_mask);
4498 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src_param);
4499
4500 if (mask_size > 1)
4501 shader_addline(buffer, "mix(mix(ivec%u(max(%s, vec%u(-2147483648.0))), ivec%u(0x7fffffff), greaterThanEqual(%s, vec%u(2147483648.0))), ivec%u(0), isnan(%s)));\n",
4502 mask_size, src_param.param_str, mask_size, mask_size, src_param.param_str, mask_size, mask_size, src_param.param_str);
4503 else
4504 shader_addline(buffer, "mix(mix(int(max(%s, -2147483648.0)), 0x7fffffff, %s >= 2147483648.0), 0, isnan(%s)));\n",
4505 src_param.param_str, src_param.param_str, src_param.param_str);
4506}

◆ shader_glsl_to_uint()

static void shader_glsl_to_uint ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4508 of file glsl_shader.c.

4509{
4510 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4511 struct glsl_src_param src_param;
4512 unsigned int mask_size;
4513 DWORD write_mask;
4514
4515 write_mask = shader_glsl_append_dst(buffer, ins);
4516 mask_size = shader_glsl_get_write_mask_size(write_mask);
4517 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src_param);
4518
4519 if (mask_size > 1)
4520 shader_addline(buffer, "mix(uvec%u(max(%s, vec%u(0.0))), uvec%u(0xffffffffu), greaterThanEqual(%s, vec%u(4294967296.0))));\n",
4521 mask_size, src_param.param_str, mask_size, mask_size, src_param.param_str, mask_size);
4522 else
4523 shader_addline(buffer, "mix(uint(max(%s, 0.0)), 0xffffffffu, %s >= 4294967296.0));\n",
4524 src_param.param_str, src_param.param_str);
4525}

◆ shader_glsl_uav_counter()

static void shader_glsl_uav_counter ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 5703 of file glsl_shader.c.

5704{
5705 const char *prefix = shader_glsl_get_prefix(ins->ctx->reg_maps->shader_version.type);
5706 const char *op;
5707
5709 op = "atomicCounterIncrement";
5710 else
5711 op = "atomicCounterDecrement";
5712
5713 shader_glsl_append_dst(ins->ctx->buffer, ins);
5714 shader_addline(ins->ctx->buffer, "%s(%s_counter%u));\n", op, prefix, ins->src[0].reg.idx[0].offset);
5715}
@ WINED3DSIH_IMM_ATOMIC_ALLOC

◆ shader_glsl_udiv()

static void shader_glsl_udiv ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 4036 of file glsl_shader.c.

4037{
4038 struct wined3d_string_buffer *buffer = ins->ctx->buffer;
4039 struct glsl_src_param src0_param, src1_param;
4040 DWORD write_mask;
4041
4042 if (ins->dst[0].reg.type != WINED3DSPR_NULL)
4043 {
4044 if (ins->dst[1].reg.type != WINED3DSPR_NULL)
4045 {
4046 char dst_mask[6];
4047
4048 write_mask = shader_glsl_get_write_mask(&ins->dst[0], dst_mask);
4049 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
4050 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
4051 shader_addline(buffer, "tmp0%s = uintBitsToFloat(%s / %s);\n",
4052 dst_mask, src0_param.param_str, src1_param.param_str);
4053
4054 write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], 1, ins->dst[1].reg.data_type);
4055 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
4056 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
4057 shader_addline(buffer, "%s %% %s);\n", src0_param.param_str, src1_param.param_str);
4058
4060 shader_addline(buffer, "tmp0%s);\n", dst_mask);
4061 }
4062 else
4063 {
4064 write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0], 0, ins->dst[0].reg.data_type);
4065 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
4066 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
4067 shader_addline(buffer, "%s / %s);\n", src0_param.param_str, src1_param.param_str);
4068 }
4069 }
4070 else if (ins->dst[1].reg.type != WINED3DSPR_NULL)
4071 {
4072 write_mask = shader_glsl_append_dst_ext(buffer, ins, &ins->dst[1], 1, ins->dst[1].reg.data_type);
4073 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src0_param);
4074 shader_glsl_add_src_param(ins, &ins->src[1], write_mask, &src1_param);
4075 shader_addline(buffer, "%s %% %s);\n", src0_param.param_str, src1_param.param_str);
4076 }
4077}

◆ shader_glsl_unary_op()

static void shader_glsl_unary_op ( const struct wined3d_shader_instruction *  ins)
static

Definition at line 3991 of file glsl_shader.c.

3992{
3993 struct glsl_src_param src_param;
3994 DWORD write_mask;
3995 const char *op;
3996
3997 switch (ins->handler_idx)
3998 {
3999 case WINED3DSIH_INEG: op = "-"; break;
4000 case WINED3DSIH_NOT: op = "~"; break;
4001 default:
4002 op = "<unhandled operator>";
4003 ERR("Unhandled opcode %s.\n",
4005 break;
4006 }
4007
4008 write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
4009 shader_glsl_add_src_param(ins, &ins->src[0], write_mask, &src_param);
4010 shader_addline(ins->ctx->buffer, "%s%s);\n", op, src_param.param_str);
4011}
@ WINED3DSIH_NOT
@ WINED3DSIH_INEG

◆ shader_glsl_update_compute_program()

static void shader_glsl_update_compute_program ( struct shader_glsl_priv *  priv,
struct wined3d_context_gl *  context_gl,
const struct wined3d_state *  state 
)
static

Definition at line 10902 of file glsl_shader.c.

10904{
10905 struct glsl_context_data *ctx_data = context_gl->c.shader_backend_data;
10906 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
10907 GLuint program_id, prev_id;
10908
10909 prev_id = ctx_data->glsl_program ? ctx_data->glsl_program->id : 0;
10910 set_glsl_compute_shader_program(context_gl, state, priv, ctx_data);
10911 program_id = ctx_data->glsl_program ? ctx_data->glsl_program->id : 0;
10912
10913 TRACE("Using GLSL program %u.\n", program_id);
10914
10915 if (prev_id != program_id)
10916 {
10917 GL_EXTCALL(glUseProgram(program_id));
10918 checkGLcall("glUseProgram");
10919 }
10920
10921 context_gl->c.shader_update_mask |= (1u << WINED3D_SHADER_TYPE_PIXEL)
10924 | (1u << WINED3D_SHADER_TYPE_HULL)
10926}
static void set_glsl_compute_shader_program(const struct wined3d_context_gl *context_gl, const struct wined3d_state *state, struct shader_glsl_priv *priv, struct glsl_context_data *ctx_data)

Referenced by shader_glsl_apply_compute_state().

◆ shader_glsl_update_float_pixel_constants()

static void shader_glsl_update_float_pixel_constants ( struct wined3d_device *  device,
UINT  start,
UINT  count 
)
static

Definition at line 2064 of file glsl_shader.c.

2065{
2066 struct shader_glsl_priv *priv = device->shader_priv;
2067 struct constant_heap *heap = &priv->pconst_heap;
2068 UINT i;
2069
2070 for (i = start; i < count + start; ++i)
2071 {
2073 }
2074}
static void update_heap_entry(struct constant_heap *heap, unsigned int idx, DWORD new_version)
Definition: glsl_shader.c:2020

◆ shader_glsl_update_float_vertex_constants()

static void shader_glsl_update_float_vertex_constants ( struct wined3d_device *  device,
UINT  start,
UINT  count 
)
static

Definition at line 2052 of file glsl_shader.c.

2053{
2054 struct shader_glsl_priv *priv = device->shader_priv;
2055 struct constant_heap *heap = &priv->vconst_heap;
2056 UINT i;
2057
2058 for (i = start; i < count + start; ++i)
2059 {
2061 }
2062}

◆ shader_glsl_update_graphics_program()

static void shader_glsl_update_graphics_program ( struct shader_glsl_priv *  priv,
struct wined3d_context_gl *  context_gl,
const struct wined3d_state *  state 
)
static

Definition at line 10828 of file glsl_shader.c.

10830{
10831 struct glsl_context_data *ctx_data = context_gl->c.shader_backend_data;
10832 const struct wined3d_gl_info *gl_info = context_gl->gl_info;
10833 struct glsl_shader_prog_link *glsl_program;
10834 GLenum current_vertex_color_clamp;
10835 GLuint program_id, prev_id;
10836
10837 priv->vertex_pipe->vp_apply_draw_state(&context_gl->c, state);
10838 priv->fragment_pipe->fp_apply_draw_state(&context_gl->c, state);
10839
10840 prev_id = ctx_data->glsl_program ? ctx_data->glsl_program->id : 0;
10841 set_glsl_shader_program(context_gl, state, priv, ctx_data);
10842 glsl_program = ctx_data->glsl_program;
10843
10844 if (glsl_program)
10845 {
10846 program_id = glsl_program->id;
10847 current_vertex_color_clamp = glsl_program->vs.vertex_color_clamp;
10848 if (glsl_program->shader_controlled_clip_distances)
10850 }
10851 else
10852 {
10853 program_id = 0;
10854 current_vertex_color_clamp = GL_FIXED_ONLY_ARB;
10855 }
10856
10857 if (ctx_data->vertex_color_clamp != current_vertex_color_clamp)
10858 {
10859 ctx_data->vertex_color_clamp = current_vertex_color_clamp;
10860 if (gl_info->supported[ARB_COLOR_BUFFER_FLOAT])
10861 {
10862 GL_EXTCALL(glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, current_vertex_color_clamp));
10863 checkGLcall("glClampColorARB");
10864 }
10865 else
10866 {
10867 FIXME("Vertex color clamp needs to be changed, but extension not supported.\n");
10868 }
10869 }
10870
10871 TRACE("Using GLSL program %u.\n", program_id);
10872
10873 if (prev_id != program_id)
10874 {
10875 GL_EXTCALL(glUseProgram(program_id));
10876 checkGLcall("glUseProgram");
10877
10878 if (glsl_program)
10879 context_gl->c.constant_update_mask |= glsl_program->constant_update_mask;
10880 }
10881
10882 context_gl->c.shader_update_mask |= (1u << WINED3D_SHADER_TYPE_COMPUTE);
10883}
void wined3d_context_gl_enable_clip_distances(struct wined3d_context_gl *context_gl, uint32_t enable_mask)
Definition: context_gl.c:2408
static void set_glsl_shader_program(const struct wined3d_context_gl *context_gl, const struct wined3d_state *state, struct shader_glsl_priv *priv, struct glsl_context_data *ctx_data)

Referenced by shader_glsl_apply_draw_state().

◆ shader_glsl_update_legacy_states()

static void shader_glsl_update_legacy_states ( struct wined3d_context_gl *  context_gl,
const struct wined3d_state *  state 
)
static

Definition at line 12325 of file glsl_shader.c.

12326{
12327 if (!context_gl->gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
12328 return;
12329
12330 if (context_gl->c.shader_update_mask & (1u << WINED3D_SHADER_TYPE_PIXEL))
12331 {
12334 }
12335
12336 if (context_gl->c.constant_update_mask & WINED3D_SHADER_CONST_PS_ALPHA_TEST)
12338}
static void glsl_fragment_pipe_alpha_test(struct wined3d_context_gl *context_gl, const struct wined3d_state *state)
static void glsl_fragment_pipe_alpha_test_func(struct wined3d_context_gl *context_gl, const struct wined3d_state *state)

Referenced by shader_glsl_apply_draw_state().

◆ shader_glsl_use_explicit_attrib_location()

static BOOL shader_glsl_use_explicit_attrib_location ( const struct wined3d_gl_info *  gl_info)
static

◆ shader_glsl_use_interface_blocks()

static BOOL shader_glsl_use_interface_blocks ( const struct wined3d_gl_info *  gl_info)
static

◆ shader_glsl_use_layout_binding_qualifier()

◆ shader_glsl_use_layout_qualifier()

static BOOL shader_glsl_use_layout_qualifier ( const struct wined3d_gl_info *  gl_info)
static

Definition at line 830 of file glsl_shader.c.

831{
832 /* Layout qualifiers were introduced in GLSL 1.40. The Nvidia Legacy GPU
833 * driver (series 340.xx) doesn't parse layout qualifiers in older GLSL
834 * versions. */
835 return shader_glsl_get_version(gl_info) >= 140;
836}

Referenced by shader_glsl_use_explicit_attrib_location(), and shader_glsl_use_layout_binding_qualifier().

◆ shader_glsl_validate_link()

void shader_glsl_validate_link ( const struct wined3d_gl_info *  gl_info,
GLuint  program 
)

Definition at line 617 of file glsl_shader.c.

618{
619 GLint tmp;
620
621 if (!TRACE_ON(d3d_shader) && !FIXME_ON(d3d_shader))
622 return;
623
624 GL_EXTCALL(glGetProgramiv(program, GL_LINK_STATUS, &tmp));
625 if (!tmp)
626 {
627 FIXME("Program %u link status invalid.\n", program);
629 }
630
632}
#define GL_LINK_STATUS
Definition: glext.h:448
static void shader_glsl_dump_program_source(const struct wined3d_gl_info *gl_info, GLuint program)
Definition: glsl_shader.c:561

Referenced by draw_test_quad(), glsl_blitter_generate_program(), set_glsl_shader_program(), and shader_glsl_compile_compute_shader().

◆ shader_glsl_write_mask_to_str()

◆ update_heap_entry()

static void update_heap_entry ( struct constant_heap *  heap,
unsigned int  idx,
DWORD  new_version 
)
static

Definition at line 2020 of file glsl_shader.c.

2021{
2022 struct constant_entry *entries = heap->entries;
2023 unsigned int *positions = heap->positions;
2024 unsigned int heap_idx, parent_idx;
2025
2026 if (!heap->contained[idx])
2027 {
2028 heap_idx = heap->size++;
2029 heap->contained[idx] = TRUE;
2030 }
2031 else
2032 {
2033 heap_idx = positions[idx];
2034 }
2035
2036 while (heap_idx > 1)
2037 {
2038 parent_idx = heap_idx >> 1;
2039
2040 if (new_version <= entries[parent_idx].version) break;
2041
2042 entries[heap_idx] = entries[parent_idx];
2043 positions[entries[parent_idx].idx] = heap_idx;
2044 heap_idx = parent_idx;
2045 }
2046
2047 entries[heap_idx].version = new_version;
2048 entries[heap_idx].idx = idx;
2049 positions[idx] = heap_idx;
2050}
Definition: glsl_shader.c:112
unsigned int version
Definition: glsl_shader.c:114
unsigned int idx
Definition: glsl_shader.c:113

Referenced by shader_glsl_update_float_pixel_constants(), and shader_glsl_update_float_vertex_constants().

◆ use_legacy_fragment_output()

static BOOL use_legacy_fragment_output ( const struct wined3d_gl_info *  gl_info)
static

Definition at line 2254 of file glsl_shader.c.

2255{
2256 /* Technically 1.30 does support user-defined fragment shader outputs but
2257 * we might not have glBindFragDataLocation() available (i.e. GL version
2258 * might be < 3.0). */
2259 return gl_info->glsl_version <= MAKEDWORD_VERSION(1, 30);
2260}

Referenced by get_fragment_output(), glsl_blitter_generate_program(), set_glsl_shader_program(), shader_glsl_generate_ffp_fragment_shader(), shader_glsl_generate_fragment_shader(), and shader_glsl_generate_ps_epilogue().

◆ vec4_varyings()

static unsigned int vec4_varyings ( DWORD  shader_major,
const struct wined3d_gl_info *  gl_info 
)
static

Definition at line 2076 of file glsl_shader.c.

2077{
2078 unsigned int ret = gl_info->limits.glsl_varyings / 4;
2079 /* 4.0 shaders do not write clip coords because d3d10 does not support user clipplanes */
2080 if(shader_major > 3) return ret;
2081
2082 /* 3.0 shaders may need an extra varying for the clip coord on some cards(mostly dx10 ones) */
2083 if (gl_info->quirks & WINED3D_QUIRK_GLSL_CLIP_VARYING) ret -= 1;
2084 return ret;
2085}
#define WINED3D_QUIRK_GLSL_CLIP_VARYING
Definition: wined3d_gl.h:323

Referenced by set_glsl_shader_program(), shader_glsl_generate_fragment_shader(), shader_glsl_generate_sm4_output_setup(), shader_glsl_generate_vs3_rasterizer_input_setup(), shader_glsl_get_register_name(), and shader_glsl_setup_vs3_output().

◆ vs_args_equal()

static BOOL vs_args_equal ( const struct vs_compile_args *  stored,
const struct vs_compile_args *  new,
const DWORD  use_map 
)
static

Definition at line 8747 of file glsl_shader.c.

8749{
8750 if ((stored->swizzle_map & use_map) != new->swizzle_map)
8751 return FALSE;
8752 if ((stored->clip_enabled) != new->clip_enabled)
8753 return FALSE;
8754 if (stored->point_size != new->point_size)
8755 return FALSE;
8756 if (stored->flatshading != new->flatshading)
8757 return FALSE;
8758 if (stored->next_shader_type != new->next_shader_type)
8759 return FALSE;
8760 if (stored->next_shader_input_count != new->next_shader_input_count)
8761 return FALSE;
8762 if (stored->fog_src != new->fog_src)
8763 return FALSE;
8764 return !memcmp(stored->interpolation_mode, new->interpolation_mode, sizeof(new->interpolation_mode));
8765}
uint32_t interpolation_mode[WINED3D_PACKED_INTERPOLATION_SIZE]
unsigned int next_shader_input_count
#define new(TYPE, numElems)
Definition: treelist.c:54

Referenced by find_glsl_vertex_shader().

◆ walk_constant_heap()

static void walk_constant_heap ( const struct wined3d_gl_info *  gl_info,
const struct wined3d_vec4 *  constants,
const GLint *  constant_locations,
const struct constant_heap *  heap,
unsigned char *  stack,
DWORD  version 
)
static

Definition at line 1225 of file glsl_shader.c.

1227{
1228 unsigned int start = ~0U, end = 0;
1229 int stack_idx = 0;
1230 unsigned int heap_idx = 1;
1231 unsigned int idx;
1232
1233 if (heap->entries[heap_idx].version <= version) return;
1234
1235 idx = heap->entries[heap_idx].idx;
1236 if (constant_locations[idx] != -1)
1237 start = end = idx;
1238 stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT;
1239
1240 while (stack_idx >= 0)
1241 {
1242 /* Note that we fall through to the next case statement. */
1243 switch(stack[stack_idx])
1244 {
1246 {
1247 unsigned int left_idx = heap_idx << 1;
1248 if (left_idx < heap->size && heap->entries[left_idx].version > version)
1249 {
1250 heap_idx = left_idx;
1251 idx = heap->entries[heap_idx].idx;
1252 if (constant_locations[idx] != -1)
1253 {
1254 if (start > idx)
1255 start = idx;
1256 if (end < idx)
1257 end = idx;
1258 }
1259
1260 stack[stack_idx++] = HEAP_NODE_TRAVERSE_RIGHT;
1261 stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT;
1262 break;
1263 }
1264 }
1265
1267 {
1268 unsigned int right_idx = (heap_idx << 1) + 1;
1269 if (right_idx < heap->size && heap->entries[right_idx].version > version)
1270 {
1271 heap_idx = right_idx;
1272 idx = heap->entries[heap_idx].idx;
1273 if (constant_locations[idx] != -1)
1274 {
1275 if (start > idx)
1276 start = idx;
1277 if (end < idx)
1278 end = idx;
1279 }
1280
1281 stack[stack_idx++] = HEAP_NODE_POP;
1282 stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT;
1283 break;
1284 }
1285 }
1286
1287 case HEAP_NODE_POP:
1288 heap_idx >>= 1;
1289 --stack_idx;
1290 break;
1291 }
1292 }
1293 if (start <= end)
1294 GL_EXTCALL(glUniform4fv(constant_locations[start], end - start + 1, &constants[start].x));
1295 checkGLcall("walk_constant_heap()");
1296}
#define U(x)
Definition: wordpad.c:45

Referenced by shader_glsl_load_constants_f().

◆ walk_constant_heap_clamped()

static void walk_constant_heap_clamped ( const struct wined3d_gl_info *  gl_info,
const struct wined3d_vec4 *  constants,
const GLint *  constant_locations,
const struct constant_heap *  heap,
unsigned char *  stack,
DWORD  version 
)
static

Definition at line 1315 of file glsl_shader.c.

1318{
1319 int stack_idx = 0;
1320 unsigned int heap_idx = 1;
1321 unsigned int idx;
1322
1323 if (heap->entries[heap_idx].version <= version) return;
1324
1325 idx = heap->entries[heap_idx].idx;
1326 apply_clamped_constant(gl_info, constant_locations[idx], &constants[idx]);
1327 stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT;
1328
1329 while (stack_idx >= 0)
1330 {
1331 /* Note that we fall through to the next case statement. */
1332 switch(stack[stack_idx])
1333 {
1335 {
1336 unsigned int left_idx = heap_idx << 1;
1337 if (left_idx < heap->size && heap->entries[left_idx].version > version)
1338 {
1339 heap_idx = left_idx;
1340 idx = heap->entries[heap_idx].idx;
1341 apply_clamped_constant(gl_info, constant_locations[idx], &constants[idx]);
1342
1343 stack[stack_idx++] = HEAP_NODE_TRAVERSE_RIGHT;
1344 stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT;
1345 break;
1346 }
1347 }
1348
1350 {
1351 unsigned int right_idx = (heap_idx << 1) + 1;
1352 if (right_idx < heap->size && heap->entries[right_idx].version > version)
1353 {
1354 heap_idx = right_idx;
1355 idx = heap->entries[heap_idx].idx;
1356 apply_clamped_constant(gl_info, constant_locations[idx], &constants[idx]);
1357
1358 stack[stack_idx++] = HEAP_NODE_POP;
1359 stack[stack_idx] = HEAP_NODE_TRAVERSE_LEFT;
1360 break;
1361 }
1362 }
1363
1364 case HEAP_NODE_POP:
1365 heap_idx >>= 1;
1366 --stack_idx;
1367 break;
1368 }
1369 }
1370 checkGLcall("walk_constant_heap_clamped()");
1371}
static void apply_clamped_constant(const struct wined3d_gl_info *gl_info, GLint location, const struct wined3d_vec4 *data)
Definition: glsl_shader.c:1299

Referenced by shader_glsl_load_constants_f().

◆ WINE_DECLARE_DEBUG_CHANNEL() [1/2]

WINE_DECLARE_DEBUG_CHANNEL ( d3d  )

◆ WINE_DECLARE_DEBUG_CHANNEL() [2/2]

WINE_DECLARE_DEBUG_CHANNEL ( winediag  )

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( d3d_shader  )

◆ wined3d_extract_interpolation_mode()

static enum wined3d_shader_interpolation_mode wined3d_extract_interpolation_mode ( const uint32_t *  packed_interpolation_mode,
unsigned int  register_idx 
)
static

Definition at line 2174 of file glsl_shader.c.

2176{
2177 return wined3d_extract_bits(packed_interpolation_mode,
2179}
static DWORD wined3d_extract_bits(const uint32_t *bitstream, unsigned int offset, unsigned int count)
#define WINED3D_PACKED_INTERPOLATION_BIT_COUNT

Referenced by shader_glsl_declare_shader_inputs(), and shader_glsl_declare_shader_outputs().

◆ wined3d_glsl_blitter_create()

struct wined3d_blitter * wined3d_glsl_blitter_create ( struct wined3d_blitter **  next,
const struct wined3d_device *  device 
)

Definition at line 13210 of file glsl_shader.c.

13212{
13213 const struct wined3d_gl_info *gl_info = &wined3d_adapter_gl(device->adapter)->gl_info;
13215
13216 if (device->shader_backend != &glsl_shader_backend)
13217 return NULL;
13218
13219 if (!gl_info->supported[ARB_VERTEX_SHADER] || !gl_info->supported[ARB_FRAGMENT_SHADER])
13220 return NULL;
13221
13222 if (!(blitter = malloc(sizeof(*blitter))))
13223 {
13224 ERR("Failed to allocate blitter.\n");
13225 return NULL;
13226 }
13227
13228 TRACE("Created blitter %p.\n", blitter);
13229
13230 blitter->blitter.ops = &glsl_blitter_ops;
13231 blitter->blitter.next = *next;
13232 string_buffer_list_init(&blitter->string_buffers);
13234 blitter->palette_texture = 0;
13235 *next = &blitter->blitter;
13236
13237 return *next;
13238}
static int glsl_blitter_args_compare(const void *key, const struct wine_rb_entry *entry)
static const struct wined3d_blitter_ops glsl_blitter_ops
struct wined3d_gl_info gl_info
Definition: wined3d_gl.h:800
struct wined3d_blitter blitter

Referenced by wined3d_device_gl_create_primary_opengl_context_cs().

Variable Documentation

◆ 

const struct { ... } component_type_info[]

◆ coord_size

◆ data_type

Definition at line 71 of file glsl_shader.c.

Referenced by constant_is_one(), constant_is_zero(), convert_raw_constant32(), d3d12_device_CheckDriverMatchingIdentifier(), data_type_is_64_bit(), data_type_is_bool(), data_type_is_floating_point(), data_type_is_integer(), debugdataspaces_ReadBusData(), debugdataspaces_WriteBusData(), DECLARE_INTERFACE_(), dst_param_init_output(), get_opcode_from_rel_op(), getDataType(), hlsl_new_expr(), image_format_for_image_read(), init_node(), init_resource_declaration(), msl_print_register_datatype(), parse_data_type(), TConfig::print_value(), record_common_user_data(), register_init_ssa_vector(), register_init_with_id(), resolve_fx_4_state_block_values(), run_add(), save_prop(), TConfig::set_value(), shader_glsl_add_src_param_ext(), shader_glsl_append_dst_ext(), shader_glsl_atomic(), shader_glsl_get_register_name(), shader_glsl_ld(), shader_glsl_ld_uav(), shader_glsl_print_src(), shader_glsl_sample(), shader_glsl_store_uav(), shader_sm1_read_immconst(), shader_sm4_read_dcl_resource(), shader_sm4_read_dst_param(), shader_sm4_read_instruction_modifier(), shader_sm4_read_param(), shader_sm4_read_src_param(), sm4_register_from_deref(), sm6_parser_dcl_register_builtin(), sm6_parser_declare_icb(), sm6_parser_declare_indexable_temp(), sm6_parser_declare_tgsm_raw(), sm6_parser_declare_tgsm_structured(), sm6_parser_emit_dx_input_register_mov(), sm6_parser_emit_reg_composite_construct(), spirv_compiler_emit_int_to_bool(), spirv_compiler_get_image_type_id(), vkd3d_component_type_from_data_type(), vkd3d_component_type_from_resource_data_type(), vkd3d_data_type_from_dxil_component_type(), VKD3D_PRINTF_FUNC(), vkd3d_spirv_get_type_id_for_data_type(), vsir_dst_param_init(), vsir_register_init(), vsir_src_param_init(), wined3d_shader_resource_bindings_add_null_srv_binding(), and write_fx_4_state_numeric_value().

◆ glsl_blitter_ops

const struct wined3d_blitter_ops glsl_blitter_ops
static
Initial value:
=
{
}
static DWORD glsl_blitter_blit(struct wined3d_blitter *blitter, enum wined3d_blit_op op, struct wined3d_context *context, struct wined3d_texture *src_texture, unsigned int src_sub_resource_idx, DWORD src_location, const RECT *src_rect, struct wined3d_texture *dst_texture, unsigned int dst_sub_resource_idx, DWORD dst_location, const RECT *dst_rect, const struct wined3d_color_key *colour_key, enum wined3d_texture_filter_type filter, const struct wined3d_format *resolve_format)
static void glsl_blitter_destroy(struct wined3d_blitter *blitter, struct wined3d_context *context)
static void glsl_blitter_clear(struct wined3d_blitter *blitter, struct wined3d_device *device, unsigned int rt_count, const struct wined3d_fb_state *fb, unsigned int rect_count, const RECT *clear_rects, const RECT *draw_rect, uint32_t flags, const struct wined3d_color *color, float depth, unsigned int stencil)

Definition at line 13203 of file glsl_shader.c.

Referenced by wined3d_glsl_blitter_create().

◆ glsl_fragment_pipe

Initial value:
=
{
.fp_apply_draw_state = glsl_fragment_pipe_apply_draw_state,
.alloc_private = glsl_fragment_pipe_alloc,
.free_private = glsl_fragment_pipe_free,
.allocate_context_data = glsl_fragment_pipe_alloc_context_data,
.color_fixup_supported = shader_glsl_color_fixup_supported,
}
static void glsl_fragment_pipe_free(struct wined3d_device *device, struct wined3d_context *context)
static unsigned int glsl_fragment_pipe_get_emul_mask(const struct wined3d_adapter *adapter)
static void glsl_fragment_pipe_apply_draw_state(struct wined3d_context *context, const struct wined3d_state *state)
static const struct wined3d_state_entry_template glsl_fragment_pipe_state_template[]
static void glsl_fragment_pipe_get_caps(const struct wined3d_adapter *adapter, struct fragment_caps *caps)
static BOOL glsl_fragment_pipe_alloc_context_data(struct wined3d_context *context)
static BOOL shader_glsl_color_fixup_supported(struct color_fixup_desc fixup)
static void glsl_fragment_pipe_disable(const struct wined3d_context *context)
static void * glsl_fragment_pipe_alloc(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
static void glsl_fragment_pipe_free_context_data(struct wined3d_context *context)

Definition at line 12311 of file glsl_shader.c.

Referenced by set_glsl_shader_program(), and wined3d_adapter_init_gl_caps().

◆ glsl_fragment_pipe_state_template

const struct wined3d_state_entry_template glsl_fragment_pipe_state_template[]
static

Definition at line 12199 of file glsl_shader.c.

◆ glsl_scalar_type

const char* glsl_scalar_type

Definition at line 72 of file glsl_shader.c.

Referenced by shader_glsl_declare_generic_vertex_attribute().

◆ glsl_shader_backend

Initial value:
=
{
}
static void shader_glsl_free(struct wined3d_device *device, struct wined3d_context *context)
static HRESULT shader_glsl_alloc(struct wined3d_device *device, const struct wined3d_vertex_pipe_ops *vertex_pipe, const struct wined3d_fragment_pipe_ops *fragment_pipe)
static BOOL shader_glsl_allocate_context_data(struct wined3d_context *context)
static void shader_glsl_init_context_state(struct wined3d_context *context)
static void shader_glsl_disable(void *shader_priv, struct wined3d_context *context)
static void shader_glsl_get_caps(const struct wined3d_adapter *adapter, struct shader_caps *caps)
static void shader_glsl_apply_compute_state(void *shader_priv, struct wined3d_context *context, const struct wined3d_state *state)
static void shader_glsl_apply_draw_state(void *shader_priv, struct wined3d_context *context, const struct wined3d_state *state)
static void shader_glsl_handle_instruction(const struct wined3d_shader_instruction *ins)
static uint64_t shader_glsl_shader_compile(struct wined3d_context *context, const struct wined3d_shader_desc *shader_desc, enum wined3d_shader_type shader_type)
static void shader_glsl_update_float_vertex_constants(struct wined3d_device *device, UINT start, UINT count)
Definition: glsl_shader.c:2052
static void shader_glsl_precompile(void *shader_priv, struct wined3d_shader *shader)
static void shader_glsl_free_context_data(struct wined3d_context *context)
static void shader_glsl_update_float_pixel_constants(struct wined3d_device *device, UINT start, UINT count)
Definition: glsl_shader.c:2064
static void shader_glsl_destroy(struct wined3d_shader *shader)

Definition at line 11693 of file glsl_shader.c.

Referenced by glsl_fragment_pipe_alloc(), glsl_vertex_pipe_vp_alloc(), shader_glsl_alloc(), wined3d_adapter_init_gl_caps(), and wined3d_glsl_blitter_create().

◆ glsl_vector_type

const char* glsl_vector_type

Definition at line 73 of file glsl_shader.c.

Referenced by shader_glsl_declare_generic_vertex_attribute().

◆ glsl_vertex_pipe

Initial value:
=
{
.vp_apply_draw_state = glsl_vertex_pipe_vp_apply_draw_state,
.vp_get_emul_mask = glsl_vertex_pipe_vp_get_emul_mask,
}
static void glsl_vertex_pipe_vp_get_caps(const struct wined3d_adapter *adapter, struct wined3d_vertex_caps *caps)
static void glsl_vertex_pipe_vp_disable(const struct wined3d_context *context)
static unsigned int glsl_vertex_pipe_vp_get_emul_mask(const struct wined3d_adapter *adapter)
static void glsl_vertex_pipe_vp_apply_draw_state(struct wined3d_context *context, const struct wined3d_state *state)
static void * glsl_vertex_pipe_vp_alloc(const struct wined3d_shader_backend_ops *shader_backend, void *shader_priv)
static void glsl_vertex_pipe_vp_free(struct wined3d_device *device, struct wined3d_context *context)
static const struct wined3d_state_entry_template glsl_vertex_pipe_vp_states[]

Definition at line 11971 of file glsl_shader.c.

Referenced by set_glsl_shader_program(), and wined3d_adapter_init_gl_caps().

◆ glsl_vertex_pipe_vp_states

const struct wined3d_state_entry_template glsl_vertex_pipe_vp_states[]
static

Definition at line 11910 of file glsl_shader.c.

◆ resinfo_size

unsigned int resinfo_size

Definition at line 51 of file glsl_shader.c.

◆ 

◆ shader_glsl_instruction_handler_table

const SHADER_HANDLER shader_glsl_instruction_handler_table[WINED3DSIH_TABLE_SIZE]
static

Definition at line 11426 of file glsl_shader.c.

Referenced by shader_glsl_handle_instruction().

◆ shift_glsl_tab

const char* const shift_glsl_tab[]
static
Initial value:
= {
"",
"2.0 * ",
"4.0 * ",
"8.0 * ",
"16.0 * ",
"32.0 * ",
"",
"",
"",
"",
"",
"",
"0.0625 * ",
"0.125 * ",
"0.25 * ",
"0.5 * "
}

Used for opcode modifiers - They multiply the result by the specified amount

Definition at line 2776 of file glsl_shader.c.

Referenced by shader_glsl_append_dst_ext().

◆ type_part

const char* type_part

Definition at line 52 of file glsl_shader.c.

Referenced by shader_glsl_get_sample_function().