From 7e040483ec8129afa80777bc97072b90ab6ad712 Mon Sep 17 00:00:00 2001 From: Alexander Slobodeniuk Date: Wed, 3 Jun 2026 16:14:40 +0200 Subject: [PATCH] radeonsi: fix conformance window emission in the SPS If the vaapi application submits SPS with pic_width_in_luma_samples not aligned to be divisible by 64, the driver overwrites it to an aligned value. But if it does so, then it should also recalculate the conformance window. Example from real life: gstreamer vah265enc built with libva < 1.21 or vaapih265enc transcoding a video of width == 854 gst-launch-1.0 uridecodebin uri=https://media.w3.org/2010/05/sintel/trailer.mp4 ! vaapih265enc ! filesink location=out.h265 The code uploads an SPS with pic_width_in_luma_samples == 864, and the driver overwrites it to 896. The conformance window provided in the SPS was 10 : 864 - 10 = 854. So after encoding the output width results in a wrong value: 896 - 10 = 886 Reviewed-by: David Rosca Part-of: --- .../drivers/radeonsi/mm/radeon_vcn_enc_1_2.c | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/radeonsi/mm/radeon_vcn_enc_1_2.c b/src/gallium/drivers/radeonsi/mm/radeon_vcn_enc_1_2.c index 383fb0d9134..8273614611e 100644 --- a/src/gallium/drivers/radeonsi/mm/radeon_vcn_enc_1_2.c +++ b/src/gallium/drivers/radeonsi/mm/radeon_vcn_enc_1_2.c @@ -203,8 +203,30 @@ unsigned int radeon_enc_write_sps(struct radeon_encoder *enc, uint8_t nal_byte, unsigned int radeon_enc_write_sps_hevc(struct radeon_encoder *enc, uint8_t *out) { struct pipe_h265_enc_seq_param sps = enc->enc_pic.hevc.desc->seq; - sps.pic_width_in_luma_samples = enc->enc_pic.session_init.aligned_picture_width; - sps.pic_height_in_luma_samples = enc->enc_pic.session_init.aligned_picture_height; + + int width_correction = enc->enc_pic.session_init.aligned_picture_width - sps.pic_width_in_luma_samples; + int height_correction = enc->enc_pic.session_init.aligned_picture_height - sps.pic_height_in_luma_samples; + sps.pic_width_in_luma_samples += width_correction; + sps.pic_height_in_luma_samples += height_correction; + + if (width_correction != 0 || + height_correction != 0) { + const int chroma_idc_div = 2; + int wcrop_correction = width_correction / chroma_idc_div; + int hcrop_correction = height_correction / chroma_idc_div; + + if (sps.conformance_window_flag) { + sps.conf_win_right_offset += wcrop_correction; + sps.conf_win_bottom_offset += hcrop_correction; + } else { + sps.conformance_window_flag = 1; + sps.conf_win_left_offset = 0; + sps.conf_win_right_offset = wcrop_correction; + sps.conf_win_top_offset = 0; + sps.conf_win_bottom_offset = hcrop_correction; + } + } + sps.log2_min_luma_coding_block_size_minus3 = enc->enc_pic.hevc_spec_misc.log2_min_luma_coding_block_size_minus3; sps.log2_diff_max_min_luma_coding_block_size = 6 - (sps.log2_min_luma_coding_block_size_minus3 + 3);