write last pixel in YCbCr conversion

This commit is contained in:
Patrick Nicolas
2024-09-18 22:26:01 +02:00
parent 801bc5bd65
commit c5d3899b87
@@ -1,4 +1,4 @@
From f04fc2ea2660105af8af3a51dbe13c638cfa68b8 Mon Sep 17 00:00:00 2001 From db34211565a0e67e3da2fc0be174bd570869efaa Mon Sep 17 00:00:00 2001
From: Patrick Nicolas <patricknicolas@laposte.net> From: Patrick Nicolas <patricknicolas@laposte.net>
Date: Wed, 11 Sep 2024 22:56:29 +0200 Date: Wed, 11 Sep 2024 22:56:29 +0200
Subject: [PATCH] Convert to YCbCr in Monado Subject: [PATCH] Convert to YCbCr in Monado
@@ -9,16 +9,16 @@ Subject: [PATCH] Convert to YCbCr in Monado
src/xrt/compositor/render/render_compute.c | 104 +++++++++++++------ src/xrt/compositor/render/render_compute.c | 104 +++++++++++++------
src/xrt/compositor/render/render_interface.h | 15 ++- src/xrt/compositor/render/render_interface.h | 15 ++-
src/xrt/compositor/render/render_resources.c | 35 +++++-- src/xrt/compositor/render/render_resources.c | 35 +++++--
src/xrt/compositor/shaders/distortion.comp | 53 +++++++--- src/xrt/compositor/shaders/distortion.comp | 55 +++++++---
src/xrt/compositor/util/comp_render.h | 12 ++- src/xrt/compositor/util/comp_render.h | 12 ++-
src/xrt/compositor/util/comp_render_cs.c | 41 +++++--- src/xrt/compositor/util/comp_render_cs.c | 41 +++++---
8 files changed, 184 insertions(+), 85 deletions(-) 8 files changed, 186 insertions(+), 85 deletions(-)
diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c
index e29b79b03..f3daf0e15 100644 index e8e1072ac..a86570665 100644
--- a/src/xrt/compositor/main/comp_renderer.c --- a/src/xrt/compositor/main/comp_renderer.c
+++ b/src/xrt/compositor/main/comp_renderer.c +++ b/src/xrt/compositor/main/comp_renderer.c
@@ -1005,7 +1005,8 @@ dispatch_compute(struct comp_renderer *r, @@ -1009,7 +1009,8 @@ dispatch_compute(struct comp_renderer *r,
// Target Vulkan resources.. // Target Vulkan resources..
VkImage target_image = r->c->target->images[r->acquired_buffer].handle; VkImage target_image = r->c->target->images[r->acquired_buffer].handle;
@@ -28,7 +28,7 @@ index e29b79b03..f3daf0e15 100644
// Target view information. // Target view information.
struct render_viewport_data views[XRT_MAX_VIEWS]; struct render_viewport_data views[XRT_MAX_VIEWS];
@@ -1016,7 +1017,8 @@ dispatch_compute(struct comp_renderer *r, @@ -1020,7 +1021,8 @@ dispatch_compute(struct comp_renderer *r,
comp_render_cs_initial_init( // comp_render_cs_initial_init( //
&data, // data &data, // data
target_image, // target_image target_image, // target_image
@@ -39,7 +39,7 @@ index e29b79b03..f3daf0e15 100644
do_timewarp); // do_timewarp do_timewarp); // do_timewarp
diff --git a/src/xrt/compositor/main/comp_target.h b/src/xrt/compositor/main/comp_target.h diff --git a/src/xrt/compositor/main/comp_target.h b/src/xrt/compositor/main/comp_target.h
index bababbe1d..806d454e6 100644 index 8a94607d4..43e556b73 100644
--- a/src/xrt/compositor/main/comp_target.h --- a/src/xrt/compositor/main/comp_target.h
+++ b/src/xrt/compositor/main/comp_target.h +++ b/src/xrt/compositor/main/comp_target.h
@@ -61,7 +61,8 @@ enum comp_target_display_timing_usage @@ -61,7 +61,8 @@ enum comp_target_display_timing_usage
@@ -487,7 +487,7 @@ index 9ae017001..c5474116f 100644
&r->compute.distortion.descriptor_set_layout); // out_descriptor_set_layout &r->compute.distortion.descriptor_set_layout); // out_descriptor_set_layout
VK_CHK_WITH_RET(ret, "create_compute_distortion_descriptor_set_layout", false); VK_CHK_WITH_RET(ret, "create_compute_distortion_descriptor_set_layout", false);
diff --git a/src/xrt/compositor/shaders/distortion.comp b/src/xrt/compositor/shaders/distortion.comp diff --git a/src/xrt/compositor/shaders/distortion.comp b/src/xrt/compositor/shaders/distortion.comp
index 9a09c03db..716d0f9f6 100644 index 9a09c03db..461aeb4ec 100644
--- a/src/xrt/compositor/shaders/distortion.comp --- a/src/xrt/compositor/shaders/distortion.comp
+++ b/src/xrt/compositor/shaders/distortion.comp +++ b/src/xrt/compositor/shaders/distortion.comp
@@ -18,7 +18,7 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; @@ -18,7 +18,7 @@ layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
@@ -520,7 +520,7 @@ index 9a09c03db..716d0f9f6 100644
vec2 position_to_uv(ivec2 extent, uint ix, uint iy) vec2 position_to_uv(ivec2 extent, uint ix, uint iy)
{ {
@@ -124,30 +137,38 @@ mat3x2 source_coord(ivec3 xyv, ivec2 extent) @@ -124,30 +137,40 @@ mat3x2 source_coord(ivec3 xyv, ivec2 extent)
void main() void main()
{ {
@@ -539,38 +539,40 @@ index 9a09c03db..716d0f9f6 100644
- if (ix >= extent.x || iy >= extent.y) { - if (ix >= extent.x || iy >= extent.y) {
- return; - return;
- } - }
+ if (ix >= extent.x || iy >= extent.y) {
+ return;
+ }
- vec2 dist_uv = position_to_uv(extent, ix, iy);
+ vec2 dist_uv = position_to_uv(extent, ix, iy); + vec2 dist_uv = position_to_uv(extent, ix, iy);
- vec2 uv = texture(distortion[iz + 0], dist_uv).xy; - vec2 dist_uv = position_to_uv(extent, ix, iy);
- vec2 lod = texture(distortion[iz + 2], dist_uv).xy;
+ vec2 uv = texture(distortion[iz + 0], dist_uv).xy; + vec2 uv = texture(distortion[iz + 0], dist_uv).xy;
+ vec2 lod = texture(distortion[iz + 2], dist_uv).xy; + vec2 lod = texture(distortion[iz + 2], dist_uv).xy;
- // Do any transformation needed. - vec2 uv = texture(distortion[iz + 0], dist_uv).xy;
- uv = transform_uv(uv, iz); - vec2 lod = texture(distortion[iz + 2], dist_uv).xy;
+ // Do any transformation needed. + // Do any transformation needed.
+ uv = transform_uv(uv, iz); + uv = transform_uv(uv, iz);
- // Sample the source - // Do any transformation needed.
- vec4 colour = textureLod(source[iz], uv, mix(lod.x, lod.y, 0.5)); - uv = transform_uv(uv, iz);
+ // Sample the source + // Sample the source
+ vec3 colour = textureLod(source[iz], uv, mix(lod.x, lod.y, 0.5)).rgb; + vec3 colour = textureLod(source[iz], uv, mix(lod.x, lod.y, 0.5)).rgb;
- // Do colour correction here since there are no automatic conversion in hardware available. - // Sample the source
- colour = vec4(from_linear_to_srgb(colour.rgb), 1); - vec4 colour = textureLod(source[iz], uv, mix(lod.x, lod.y, 0.5));
+ colour = rgb_to_ycbcr(from_linear_to_srgb(colour)); + colour = rgb_to_ycbcr(from_linear_to_srgb(colour));
- imageStore(target, ivec2(offset.x + ix, offset.y + iy), colour); - // Do colour correction here since there are no automatic conversion in hardware available.
+ imageStore(luma, ivec2(offset.x + ix, offset.y + iy), vec4(colour.x)); - colour = vec4(from_linear_to_srgb(colour.rgb), 1);
+ int i = k * 2 + j; + int i = k * 2 + j;
+ cbcrs[i] = colour.yz; + cbcrs[i] = colour.yz;
- imageStore(target, ivec2(offset.x + ix, offset.y + iy), colour);
+ if (ix < extent.x && iy < extent.y) {
+ imageStore(luma, ivec2(offset.x + ix, offset.y + iy), vec4(colour.x));
+ }
+ } + }
+ } + }
+ if (gl_GlobalInvocationID.x >= extent.x || gl_GlobalInvocationID.y >= extent.y) {
+ return;
+ }
+ vec2 cbcr = mix(mix(cbcrs[0], cbcrs[1], 0.5), mix(cbcrs[2], cbcrs[3], 0.5), 0.5); + vec2 cbcr = mix(mix(cbcrs[0], cbcrs[1], 0.5), mix(cbcrs[2], cbcrs[3], 0.5), 0.5);
+ imageStore(chroma, ivec2(offset.xy/2 + gl_GlobalInvocationID.xy), vec4(cbcr.x, cbcr.y, 0, 0)); + imageStore(chroma, ivec2(offset.xy/2 + gl_GlobalInvocationID.xy), vec4(cbcr.x, cbcr.y, 0, 0));
} }
@@ -619,10 +621,10 @@ index da717aa91..69234bac4 100644
bool do_timewarp); bool do_timewarp);
diff --git a/src/xrt/compositor/util/comp_render_cs.c b/src/xrt/compositor/util/comp_render_cs.c diff --git a/src/xrt/compositor/util/comp_render_cs.c b/src/xrt/compositor/util/comp_render_cs.c
index e85cd511a..34cc27ece 100644 index fe5a480de..7e261fd3c 100644
--- a/src/xrt/compositor/util/comp_render_cs.c --- a/src/xrt/compositor/util/comp_render_cs.c
+++ b/src/xrt/compositor/util/comp_render_cs.c +++ b/src/xrt/compositor/util/comp_render_cs.c
@@ -330,11 +330,12 @@ do_cs_clear(struct render_compute *crc, const struct comp_render_dispatch_data * @@ -350,11 +350,12 @@ do_cs_clear(struct render_compute *crc, const struct comp_render_dispatch_data *
} }
@@ -640,7 +642,7 @@ index e85cd511a..34cc27ece 100644
} }
static void static void
@@ -458,14 +459,15 @@ do_cs_distortion_from_scratch(struct render_compute *crc, const struct comp_rend @@ -478,14 +479,15 @@ do_cs_distortion_from_scratch(struct render_compute *crc, const struct comp_rend
src_norm_rects[i] = src_norm_rect; src_norm_rects[i] = src_norm_rect;
} }
@@ -664,7 +666,7 @@ index e85cd511a..34cc27ece 100644
} }
static void static void
@@ -535,7 +537,8 @@ do_cs_distortion_for_layer(struct render_compute *crc, @@ -555,7 +557,8 @@ do_cs_distortion_for_layer(struct render_compute *crc,
src_image_views, // src_image_views, //
src_norm_rects, // src_norm_rects, //
d->cs.target_image, // d->cs.target_image, //
@@ -674,7 +676,7 @@ index e85cd511a..34cc27ece 100644
target_viewport_datas); // target_viewport_datas); //
} else { } else {
render_compute_projection_timewarp( // render_compute_projection_timewarp( //
@@ -547,7 +550,8 @@ do_cs_distortion_for_layer(struct render_compute *crc, @@ -567,7 +570,8 @@ do_cs_distortion_for_layer(struct render_compute *crc,
src_fovs, // src_fovs, //
world_poses, // world_poses, //
d->cs.target_image, // d->cs.target_image, //
@@ -684,7 +686,7 @@ index e85cd511a..34cc27ece 100644
target_viewport_datas); // target_viewport_datas); //
} }
} }
@@ -568,7 +572,8 @@ comp_render_cs_layer(struct render_compute *crc, @@ -588,7 +592,8 @@ comp_render_cs_layer(struct render_compute *crc,
const struct xrt_pose *world_pose, const struct xrt_pose *world_pose,
const struct xrt_pose *eye_pose, const struct xrt_pose *eye_pose,
const VkImage target_image, const VkImage target_image,
@@ -694,7 +696,7 @@ index e85cd511a..34cc27ece 100644
const struct render_viewport_data *target_view, const struct render_viewport_data *target_view,
bool do_timewarp) bool do_timewarp)
{ {
@@ -729,7 +734,8 @@ comp_render_cs_layer(struct render_compute *crc, @@ -749,7 +754,8 @@ comp_render_cs_layer(struct render_compute *crc,
src_samplers, // src_samplers, //
src_image_views, // src_image_views, //
cur_image, // cur_image, //
@@ -704,7 +706,7 @@ index e85cd511a..34cc27ece 100644
target_view, // target_view, //
do_timewarp); // do_timewarp); //
} }
@@ -765,6 +771,7 @@ comp_render_cs_layers(struct render_compute *crc, @@ -785,6 +791,7 @@ comp_render_cs_layers(struct render_compute *crc,
&view->eye_pose, // &view->eye_pose, //
view->image, // view->image, //
view->cs.unorm_view, // view->cs.unorm_view, //