From 1b801a95ae04ac5e7364c8969ab92dfe366d31a7 Mon Sep 17 00:00:00 2001 From: Sil Vilerino Date: Tue, 27 May 2025 17:21:39 -0400 Subject: [PATCH] pipe: Add video encode PSNR output stats Reviewed-by: Ruijing Dong Reviewed-by: Pohsiang (John) Hsu Reviewed-by: Jesse Natalie Part-of: --- src/gallium/include/pipe/p_video_enums.h | 12 ++++++++++++ src/gallium/include/pipe/p_video_state.h | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/gallium/include/pipe/p_video_enums.h b/src/gallium/include/pipe/p_video_enums.h index 53a86d24671..39c0bcef08a 100644 --- a/src/gallium/include/pipe/p_video_enums.h +++ b/src/gallium/include/pipe/p_video_enums.h @@ -243,6 +243,18 @@ enum pipe_video_cap * Support for two pass encode in encoder picture params pipe_enc_cap_two_pass */ PIPE_VIDEO_CAP_ENC_TWO_PASS = 66, + /* + * Support for the frame's PSNR to be written into a PIPE_BUFFER + * during the encoding of a frame + * + * Note that this may be written during the encode operation, before the + * get_feedback operation, since it's written into a GPU memory allocation + * + * The returned value is pipe_enc_cap_gpu_stats_psnr, which indicates + * more information about the number of PSNR components returned and their + * data layout + */ + PIPE_VIDEO_CAP_ENC_GPU_STATS_PSNR = 67, }; enum pipe_video_h264_enc_dbk_filter_mode_flags diff --git a/src/gallium/include/pipe/p_video_state.h b/src/gallium/include/pipe/p_video_state.h index e462d863414..f9a7a8d4346 100644 --- a/src/gallium/include/pipe/p_video_state.h +++ b/src/gallium/include/pipe/p_video_state.h @@ -959,6 +959,8 @@ struct pipe_h264_enc_picture_desc struct pipe_resource *gpu_stats_satd_map; /* See PIPE_VIDEO_CAP_ENC_GPU_STATS_RATE_CONTROL_BITS_MAP */ struct pipe_resource *gpu_stats_rc_bitallocation_map; + /* See PIPE_VIDEO_CAP_ENC_GPU_STATS_PSNR */ + struct pipe_resource *gpu_stats_psnr; /* See PIPE_VIDEO_CAP_ENC_QP_MAPS */ struct pipe_resource *input_gpu_qpmap; @@ -1357,6 +1359,8 @@ struct pipe_h265_enc_picture_desc struct pipe_resource *gpu_stats_satd_map; /* See PIPE_VIDEO_CAP_ENC_GPU_STATS_RATE_CONTROL_BITS_MAP */ struct pipe_resource *gpu_stats_rc_bitallocation_map; + /* See PIPE_VIDEO_CAP_ENC_GPU_STATS_PSNR */ + struct pipe_resource *gpu_stats_psnr; /* See PIPE_VIDEO_CAP_ENC_QP_MAPS */ struct pipe_resource *input_gpu_qpmap; @@ -2792,6 +2796,24 @@ union pipe_enc_cap_gpu_stats_map { uint32_t value; }; +/* Used with PIPE_VIDEO_CAP_ENC_GPU_STATS_PSNR */ +union pipe_enc_cap_gpu_stats_psnr { + struct { + /* + * Driver Output. Indicates support for writing the frame's PSNR into a + * PIPE_BUFFER during encode frame execution as 32 bit float components + * + * The components are always written in Y, U, V order as packed + * 32 bit floats in the gpu_stats_psnr buffer sent down to the driver + * in the picture parameters. The unsupported channels are written as zero. + */ + uint32_t supports_y_channel: 1; + uint32_t supports_u_channel: 1; + uint32_t supports_v_channel: 1; + } bits; + uint32_t value; +}; + /* Used with PIPE_VIDEO_CAP_ENC_SLICED_NOTIFICATIONS */ union pipe_enc_cap_sliced_notifications { struct {