render: introduce Gamma 2.2 color transform

This commit is contained in:
Félix Poisot 2025-08-17 15:51:26 +00:00
parent 6978509f64
commit c2d9ae2142
9 changed files with 31 additions and 1 deletions

View file

@ -246,6 +246,9 @@ static bool render_pass_submit(struct wlr_render_pass *wlr_pass) {
case WLR_COLOR_TRANSFER_FUNCTION_ST2084_PQ:
pipeline = render_buffer->two_pass.render_setup->output_pipe_pq;
break;
case WLR_COLOR_TRANSFER_FUNCTION_GAMMA22:
pipeline = render_buffer->two_pass.render_setup->output_pipe_gamma22;
break;
}
struct wlr_color_luminances srgb_lum, dst_lum;
@ -796,6 +799,9 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
case WLR_COLOR_TRANSFER_FUNCTION_ST2084_PQ:
tex_transform = WLR_VK_TEXTURE_TRANSFORM_ST2084_PQ;
break;
case WLR_COLOR_TRANSFER_FUNCTION_GAMMA22:
tex_transform = WLR_VK_TEXTURE_TRANSFORM_GAMMA22;
break;
}
struct wlr_vk_pipeline *pipe = setup_get_or_create_pipeline(
@ -840,7 +846,8 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
}
float luminance_multiplier = 1;
if (tf != WLR_COLOR_TRANSFER_FUNCTION_SRGB) {
if (tf != WLR_COLOR_TRANSFER_FUNCTION_SRGB
&& tf != WLR_COLOR_TRANSFER_FUNCTION_GAMMA22) {
struct wlr_color_luminances src_lum, srgb_lum;
wlr_color_transfer_function_get_default_luminance(tf, &src_lum);
wlr_color_transfer_function_get_default_luminance(

View file

@ -175,6 +175,7 @@ static void destroy_render_format_setup(struct wlr_vk_renderer *renderer,
vkDestroyPipeline(dev, setup->output_pipe_srgb, NULL);
vkDestroyPipeline(dev, setup->output_pipe_pq, NULL);
vkDestroyPipeline(dev, setup->output_pipe_lut3d, NULL);
vkDestroyPipeline(dev, setup->output_pipe_gamma22, NULL);
struct wlr_vk_pipeline *pipeline, *tmp_pipeline;
wl_list_for_each_safe(pipeline, tmp_pipeline, &setup->pipelines, link) {
@ -2345,6 +2346,11 @@ static struct wlr_vk_render_format_setup *find_or_create_render_setup(
&setup->output_pipe_pq, WLR_VK_OUTPUT_TRANSFORM_INVERSE_ST2084_PQ)) {
goto error;
}
if (!init_blend_to_output_pipeline(
renderer, setup->render_pass, renderer->output_pipe_layout,
&setup->output_pipe_gamma22, WLR_VK_OUTPUT_TRANSFORM_INVERSE_GAMMA22)) {
goto error;
}
} else {
assert(format->vk_srgb);
VkAttachmentDescription attachment = {

View file

@ -22,6 +22,7 @@ layout (constant_id = 0) const int OUTPUT_TRANSFORM = 0;
#define OUTPUT_TRANSFORM_INVERSE_SRGB 1
#define OUTPUT_TRANSFORM_INVERSE_ST2084_PQ 2
#define OUTPUT_TRANSFORM_LUT_3D 3
#define OUTPUT_TRANSFORM_INVERSE_GAMMA22 4
float linear_channel_to_srgb(float x) {
return max(min(x * 12.92, 0.04045), 1.055 * pow(x, 1. / 2.4) - 0.055);
@ -71,6 +72,8 @@ void main() {
} else if (OUTPUT_TRANSFORM == OUTPUT_TRANSFORM_INVERSE_SRGB) {
// Produce sRGB encoded values
rgb = linear_color_to_srgb(rgb);
} else if (OUTPUT_TRANSFORM == OUTPUT_TRANSFORM_INVERSE_GAMMA22) {
rgb = pow(rgb, vec3(1. / 2.2));
}
// Back to pre-multiplied alpha

View file

@ -18,6 +18,7 @@ layout (constant_id = 0) const int TEXTURE_TRANSFORM = 0;
#define TEXTURE_TRANSFORM_IDENTITY 0
#define TEXTURE_TRANSFORM_SRGB 1
#define TEXTURE_TRANSFORM_ST2084_PQ 2
#define TEXTURE_TRANSFORM_GAMMA22 3
float srgb_channel_to_linear(float x) {
return mix(x / 12.92,
@ -60,6 +61,8 @@ void main() {
rgb = srgb_color_to_linear(rgb);
} else if (TEXTURE_TRANSFORM == TEXTURE_TRANSFORM_ST2084_PQ) {
rgb = pq_color_to_linear(rgb);
} else if (TEXTURE_TRANSFORM == TEXTURE_TRANSFORM_GAMMA22) {
rgb = pow(rgb, vec3(2.2));
}
rgb *= data.luminance_multiplier;