diff --git a/include/wlr/render/pass.h b/include/wlr/render/pass.h index b8854bbf9..8e22bdf8f 100644 --- a/include/wlr/render/pass.h +++ b/include/wlr/render/pass.h @@ -104,6 +104,8 @@ struct wlr_render_texture_options { enum wlr_render_blend_mode blend_mode; /* Transfer function the source texture is encoded with */ enum wlr_color_transfer_function transfer_function; + /* Primaries describing the color volume of the source texture */ + const struct wlr_color_primaries *primaries; /* Wait for a timeline synchronization point before texturing. * diff --git a/render/vulkan/pass.c b/render/vulkan/pass.c index 30cd0fe54..0ff4f52c6 100644 --- a/render/vulkan/pass.c +++ b/render/vulkan/pass.c @@ -833,7 +833,21 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass, } float color_matrix[9]; - wlr_matrix_identity(color_matrix); + if (options->primaries != NULL) { + struct wlr_color_primaries srgb; + wlr_color_primaries_from_named(&srgb, WLR_COLOR_NAMED_PRIMARIES_SRGB); + + float src_primaries_to_xyz[9]; + wlr_color_primaries_to_xyz(options->primaries, src_primaries_to_xyz); + float srgb_to_xyz[9]; + wlr_color_primaries_to_xyz(&srgb, srgb_to_xyz); + float xyz_to_srgb[9]; + matrix_invert(xyz_to_srgb, srgb_to_xyz); + + wlr_matrix_multiply(color_matrix, xyz_to_srgb, src_primaries_to_xyz); + } else { + wlr_matrix_identity(color_matrix); + } struct wlr_vk_frag_texture_pcr_data frag_pcr_data = { .alpha = alpha,