@ -4,6 +4,7 @@
* Copyright 2016 NVIDIA Corporation
* Copyright 2016 NVIDIA Corporation
* Copyright 2019 Harish Krupo
* Copyright 2019 Harish Krupo
* Copyright 2019 Intel Corporation
* Copyright 2019 Intel Corporation
* Copyright 2021 Advanced Micro Devices , Inc .
*
*
* Permission is hereby granted , free of charge , to any person obtaining
* Permission is hereby granted , free of charge , to any person obtaining
* a copy of this software and associated documentation files ( the
* a copy of this software and associated documentation files ( the
@ -60,6 +61,12 @@ struct gl_shader {
GLint color_uniform ;
GLint color_uniform ;
GLint color_pre_curve_lut_2d_uniform ;
GLint color_pre_curve_lut_2d_uniform ;
GLint color_pre_curve_lut_scale_offset_uniform ;
GLint color_pre_curve_lut_scale_offset_uniform ;
union {
struct {
GLint tex_uniform ;
GLint scale_offset_uniform ;
} lut3d ;
} color_mapping ;
struct wl_list link ; /* gl_renderer::shader_list */
struct wl_list link ; /* gl_renderer::shader_list */
struct timespec last_used ;
struct timespec last_used ;
} ;
} ;
@ -97,6 +104,19 @@ gl_shader_color_curve_to_string(enum gl_shader_color_curve kind)
return " !?!? " ; /* never reached */
return " !?!? " ; /* never reached */
}
}
static const char *
gl_shader_color_mapping_to_string ( enum gl_shader_color_mapping kind )
{
switch ( kind ) {
# define CASERET(x) case x: return #x;
CASERET ( SHADER_COLOR_MAPPING_IDENTITY )
CASERET ( SHADER_COLOR_MAPPING_3DLUT )
# undef CASERET
}
return " !?!? " ; /* never reached */
}
static void
static void
dump_program_with_line_numbers ( int count , const char * * sources )
dump_program_with_line_numbers ( int count , const char * * sources )
{
{
@ -162,9 +182,10 @@ create_shader_description_string(const struct gl_shader_requirements *req)
int size ;
int size ;
char * str ;
char * str ;
size = asprintf ( & str , " %s %s %cinput_is_premult %cgreen " ,
size = asprintf ( & str , " %s %s %s % cinput_is_premult %cgreen " ,
gl_shader_texture_variant_to_string ( req - > variant ) ,
gl_shader_texture_variant_to_string ( req - > variant ) ,
gl_shader_color_curve_to_string ( req - > color_pre_curve ) ,
gl_shader_color_curve_to_string ( req - > color_pre_curve ) ,
gl_shader_color_mapping_to_string ( req - > color_mapping ) ,
req - > input_is_premult ? ' + ' : ' - ' ,
req - > input_is_premult ? ' + ' : ' - ' ,
req - > green_tint ? ' + ' : ' - ' ) ;
req - > green_tint ? ' + ' : ' - ' ) ;
if ( size < 0 )
if ( size < 0 )
@ -182,10 +203,12 @@ create_shader_config_string(const struct gl_shader_requirements *req)
" #define DEF_GREEN_TINT %s \n "
" #define DEF_GREEN_TINT %s \n "
" #define DEF_INPUT_IS_PREMULT %s \n "
" #define DEF_INPUT_IS_PREMULT %s \n "
" #define DEF_COLOR_PRE_CURVE %s \n "
" #define DEF_COLOR_PRE_CURVE %s \n "
" #define DEF_COLOR_MAPPING %s \n "
" #define DEF_VARIANT %s \n " ,
" #define DEF_VARIANT %s \n " ,
req - > green_tint ? " true " : " false " ,
req - > green_tint ? " true " : " false " ,
req - > input_is_premult ? " true " : " false " ,
req - > input_is_premult ? " true " : " false " ,
gl_shader_color_curve_to_string ( req - > color_pre_curve ) ,
gl_shader_color_curve_to_string ( req - > color_pre_curve ) ,
gl_shader_color_mapping_to_string ( req - > color_mapping ) ,
gl_shader_texture_variant_to_string ( req - > variant ) ) ;
gl_shader_texture_variant_to_string ( req - > variant ) ) ;
if ( size < 0 )
if ( size < 0 )
return NULL ;
return NULL ;
@ -268,6 +291,16 @@ gl_shader_create(struct gl_renderer *gr,
shader - > color_pre_curve_lut_scale_offset_uniform =
shader - > color_pre_curve_lut_scale_offset_uniform =
glGetUniformLocation ( shader - > program , " color_pre_curve_lut_scale_offset " ) ;
glGetUniformLocation ( shader - > program , " color_pre_curve_lut_scale_offset " ) ;
switch ( requirements - > color_mapping ) {
case SHADER_COLOR_MAPPING_3DLUT :
shader - > color_mapping . lut3d . tex_uniform =
glGetUniformLocation ( shader - > program , " color_mapping_lut_3d " ) ;
shader - > color_mapping . lut3d . scale_offset_uniform =
glGetUniformLocation ( shader - > program , " color_mapping_lut_scale_offset " ) ;
break ;
case SHADER_COLOR_MAPPING_IDENTITY :
break ;
}
free ( conf ) ;
free ( conf ) ;
wl_list_insert ( & gr - > shader_list , & shader - > link ) ;
wl_list_insert ( & gr - > shader_list , & shader - > link ) ;
@ -376,6 +409,7 @@ gl_renderer_create_fallback_shader(struct gl_renderer *gr)
. variant = SHADER_VARIANT_SOLID ,
. variant = SHADER_VARIANT_SOLID ,
. input_is_premult = true ,
. input_is_premult = true ,
. color_pre_curve = SHADER_COLOR_CURVE_IDENTITY ,
. color_pre_curve = SHADER_COLOR_CURVE_IDENTITY ,
. color_mapping = SHADER_COLOR_MAPPING_IDENTITY ,
} ;
} ;
struct gl_shader * shader ;
struct gl_shader * shader ;
@ -497,9 +531,8 @@ gl_shader_load_config(struct gl_shader *shader,
glTexParameteri ( in_tgt , GL_TEXTURE_MAG_FILTER , in_filter ) ;
glTexParameteri ( in_tgt , GL_TEXTURE_MAG_FILTER , in_filter ) ;
}
}
/* Fixed texture unit for color_pre_curve LUT */
/* Fixed texture unit for color_pre_curve LUT if it is available */
i = GL_SHADER_INPUT_TEX_MAX ;
i = GL_SHADER_INPUT_TEX_MAX ;
glActiveTexture ( GL_TEXTURE0 + i ) ;
switch ( sconf - > req . color_pre_curve ) {
switch ( sconf - > req . color_pre_curve ) {
case SHADER_COLOR_CURVE_IDENTITY :
case SHADER_COLOR_CURVE_IDENTITY :
assert ( sconf - > color_pre_curve_lut_tex = = 0 ) ;
assert ( sconf - > color_pre_curve_lut_tex = = 0 ) ;
@ -508,13 +541,32 @@ gl_shader_load_config(struct gl_shader *shader,
assert ( sconf - > color_pre_curve_lut_tex ! = 0 ) ;
assert ( sconf - > color_pre_curve_lut_tex ! = 0 ) ;
assert ( shader - > color_pre_curve_lut_2d_uniform ! = - 1 ) ;
assert ( shader - > color_pre_curve_lut_2d_uniform ! = - 1 ) ;
assert ( shader - > color_pre_curve_lut_scale_offset_uniform ! = - 1 ) ;
assert ( shader - > color_pre_curve_lut_scale_offset_uniform ! = - 1 ) ;
glActiveTexture ( GL_TEXTURE0 + i ) ;
glBindTexture ( GL_TEXTURE_2D , sconf - > color_pre_curve_lut_tex ) ;
glBindTexture ( GL_TEXTURE_2D , sconf - > color_pre_curve_lut_tex ) ;
glUniform1i ( shader - > color_pre_curve_lut_2d_uniform , i ) ;
glUniform1i ( shader - > color_pre_curve_lut_2d_uniform , i ) ;
i + + ;
glUniform2fv ( shader - > color_pre_curve_lut_scale_offset_uniform ,
glUniform2fv ( shader - > color_pre_curve_lut_scale_offset_uniform ,
1 , sconf - > color_pre_curve_lut_scale_offset ) ;
1 , sconf - > color_pre_curve_lut_scale_offset ) ;
break ;
break ;
}
}
switch ( sconf - > req . color_mapping ) {
case SHADER_COLOR_MAPPING_IDENTITY :
break ;
case SHADER_COLOR_MAPPING_3DLUT :
assert ( shader - > color_mapping . lut3d . tex_uniform ! = - 1 ) ;
assert ( sconf - > color_mapping . lut3d . tex ! = 0 ) ;
assert ( shader - > color_mapping . lut3d . scale_offset_uniform ! = - 1 ) ;
glActiveTexture ( GL_TEXTURE0 + i ) ;
glBindTexture ( GL_TEXTURE_3D , sconf - > color_mapping . lut3d . tex ) ;
glUniform1i ( shader - > color_mapping . lut3d . tex_uniform , i ) ;
glUniform2fv ( shader - > color_mapping . lut3d . scale_offset_uniform ,
1 , sconf - > color_mapping . lut3d . scale_offset ) ;
break ;
default :
assert ( false ) ;
break ;
}
}
}
bool
bool