Vulkan Video H.265 encode: chroma drifts without bound in the first 64 CTUs of the top CTU row at 3840x2160 (encoder/decoder reference mismatch)

Summary

When a static 3840x2160 scene is encoded with Vulkan Video H.265 (VK_KHR_video_encode_h265, through FFmpeg’s hevc_vulkan) as a long run of P-frames, the decoded chroma in CTUs 0-63 of CTU row 0 (the top 32 luma rows, x = 0-2047) gets worse with every frame. U/V PSNR in that region falls from about 41 dB to about 12-13 dB after 300 frames. Luma does not drift, and every other CTU in the picture stays at about 51.6 dB.

The bitstream itself is consistent: FFmpeg’s software HEVC decoder, NVDEC (-hwaccel cuda) and Vulkan Video decode (-hwaccel vulkan) all produce bit-identical output (same framemd5) for the whole stream. So the encoder’s internal reference picture for those CTUs must differ from what the bitstream describes. The encoder keeps predicting from its own reference while the decoder accumulates an error it never gets told about.

Things that do not drift:

  • the same FFmpeg command on the same machine with Mesa RADV (AMD VCN 4, Vulkan Video encode)
  • hevc_nvenc and h264_vulkan on the same RTX 4090
  • hevc_vulkan at 1920x1080, 2560x1440, 3840x1080 or 1920x2160

Real-world impact: game streaming hosts that use Vulkan encode (for example Sunshine with encoder = vulkan) show colour “mold” that keeps growing in the top-left corner of the screen whenever the picture is static. An IDR or a scene change clears it.

Environment

GPU NVIDIA GeForce RTX 4090 (AD102, PCI device 0x2684)
Driver 610.57.04, open kernel modules (nvidia-open-dkms 610.57.04, nvidia-utils 610.57.04)
OS / kernel Arch Linux, kernel 7.2.3-arch1-3
Vulkan loader vulkan-icd-loader 1.4.357
FFmpeg 9.0.1 (Arch ffmpeg 2:9.0.1-4). Also seen with libavcodec 62.28 as bundled in a Sunshine build.
CPU AMD Ryzen 9 7900X. Its iGPU (RADV, Mesa 26.2.2) was used as the cross-vendor control.

The encode runs headless (no display involved). The same machine also runs a Wayland session.

Steps to reproduce

The attached script hevc-vulkan-chroma-drift-repro.sh does the following:

  1. Generates its own deterministic 3840x2160 test image (colour gradients plus static noise; no external content).
  2. Encodes that image 300 times at 60 fps with hevc_vulkan.
  3. Decodes the result with FFmpeg’s software HEVC decoder.
  4. Prints PSNR against the source for the whole frame and for regions of the top CTU row.
./hevc-vulkan-chroma-drift-repro.sh                          # hevc_vulkan, 3840x2160, 300 frames (~5 s)
./hevc-vulkan-chroma-drift-repro.sh 3840 2160 300 hevc_nvenc  # control: NVENC API, same GPU
VK_DEVICE=1 ./hevc-vulkan-chroma-drift-repro.sh               # control: another Vulkan device, if present

The encode it runs:

ffmpeg -init_hw_device vulkan=vk:0 -filter_hw_device vk \
  -readrate 1 -loop 1 -framerate 60 -i still.png -frames:v 300 \
  -vf "scale=out_color_matrix=bt709:out_range=pc,format=nv12,hwupload" -color_range pc -colorspace bt709 \
  -c:v hevc_vulkan -b:v 80M -maxrate 80M -bufsize 1333333 -g 32767 -bf 0 \
  -rc_mode cbr -tune ll -usage stream -content rendered -async_depth 1 out.mkv

Settings: CBR at 80 Mbps with a one-frame VBV, a single IDR followed by P-frames only, and no B-frames. This is a typical low-latency streaming configuration.

The SPS/PPS written for this stream:

  • Main profile, 3840x2176 coded size, conformance window bottom offset 8
  • 32x32 CTB
  • SAO enabled (slice_sao_luma_flag = slice_sao_chroma_flag = 1)
  • AMP and transform skip enabled, cu_qp_delta_enabled_flag = 1
  • no tiles or WPP, one slice per picture, no temporal MVP

Expected result

On a static scene, PSNR rises over the first frames and then plateaus. Every region of the picture should stay near the whole-frame value, as it does with hevc_nvenc and with hevc_vulkan on another vendor’s driver.

Actual result

Luma plateaus. Chroma in the left 2048 px of the top 32 px row degrades with every frame.

PSNR in dB (Y / U / V) against the source, software decode, synthetic test image:

hevc_vulkan, NVIDIA 610.57.04 (RTX 4090)

frame full frame rows 0-31, x < 2048 rows 0-31, x >= 2048 rows 32-end
2 37.42 / 39.63 / 39.23 37.67 / 40.95 / 40.49 37.71 / 40.47 / 39.82 37.41 / 39.61 / 39.22
60 48.40 / 44.42 / 45.61 48.93 / 25.91 / 28.34 48.90 / 48.51 / 48.63 48.39 / 47.95 / 47.95
120 51.45 / 38.59 / 41.18 51.70 / 17.83 / 20.66 51.66 / 50.80 / 50.88 51.44 / 50.79 / 50.78
300 52.41 / 33.24 / 34.20 52.50 / 12.28 / 13.25 52.44 / 51.64 / 51.73 52.41 / 51.65 / 51.64

Control: hevc_nvenc, same GPU and driver (-rc cbr -tune ll -preset p1, same rate and VBV)

frame full frame rows 0-31, x < 2048 rows 0-31, x >= 2048 rows 32-end
60 48.73 / 48.36 / 48.37 48.79 / 48.42 / 48.45 48.83 / 48.43 / 48.48 48.73 / 48.36 / 48.37
300 52.31 / 51.55 / 51.56 52.41 / 51.55 / 51.70 52.51 / 51.58 / 51.79 52.31 / 51.55 / 51.55

Control: hevc_vulkan, identical command, Mesa 26.2.2 RADV on the AMD iGPU (VCN 4)

frame full frame rows 0-31, x < 2048 rows 0-31, x >= 2048 rows 32-end
60 45.70 / 52.27 / 52.26 45.70 / 52.89 / 53.01 45.65 / 52.83 / 52.94 45.70 / 52.26 / 52.25
300 45.70 / 54.71 / 54.68 45.70 / 54.42 / 54.75 45.65 / 54.47 / 54.68 45.70 / 54.71 / 54.68

Where the error is

I computed per-CTB chroma MSE on the decoded frames.

At frames 60, 120 and 300, exactly 64 CTBs exceed MSE 10. They are CTB addresses 0-63: row 0, columns 0-63, covering x = 0-2047. Every one of them is affected. All other CTBs, including row 0 columns 64-119, stay below MSE 1.

Within the affected CTBs, the error is uniform over all 32 rows; it is not concentrated at the picture’s top edge. Measured on 8-row bands of the top row at frame 300:

rows U PSNR V PSNR
0-7 15.2 15.6
8-15 14.8 16.2
16-23 14.9 15.9
24-31 15.2 16.3

Luma in those CTBs is fine: the largest per-CTB luma MSE in the whole frame is 0.49 at frame 300.

The same 64-CTB footprint shows up with a real 4K desktop capture instead of the synthetic image (600 frames, same settings). At frame 600 the top row is at U 19.74 / V 17.38 dB. CTBs 0-63 of row 0 have a median chroma MSE of 1698, against 0.3 for columns 64-119. A 10-bit (p010, Main 10) encode of that capture shows the same CTB range.

Decoders agree, so the bitstream is consistent

For the drifting stream, all three decoders below give the same framemd5 for all 300 frames:

  • ffmpeg -i out.mkv (libavcodec software)
  • ffmpeg -hwaccel cuda -i out.mkv (NVDEC)
  • ffmpeg -hwaccel vulkan -i out.mkv (Vulkan Video decode)

This includes NVIDIA’s own decoder. The artifact is therefore in what the encoder put in the bitstream. A conforming encoder that kept an accurate reference would see the growing error and correct it.

Encoder settings tried (all 3840x2160, hevc_vulkan, NVIDIA)

All of these drift, with the same top-left footprint wherever it was measured. Values are whole-frame PSNR, Y / U / V, from the real-capture source:

variant (otherwise as above) frame 60 frame 300
base: CBR, -tune ll 55.3 / 49.6 / 47.1 55.5 / 38.0 / 35.7 (frame 600: 37.9 / 35.6 chroma)
-tune hq, -tune default identical output to ll
-tune ull 54.2 / 46.1 / 44.0 54.2 / 37.0 / 35.2
-rc_mode vbr 55.3 / 49.7 / 47.3 55.5 / 38.0 / 35.9
-quality 1 55.3 / 50.0 / 47.8 55.5 / 38.2 / 35.7
-quality 2 (3 and 4 similar) 52.0 / 41.5 / 40.3 52.0 / 32.2 / 31.6
-async_depth 2; usage/content left at default or desktop same as base same as base
10-bit (p010, Main 10) 53.0 / 49.9 / 49.1 53.0 / 37.9 / 36.9 (frame 600: 33.1 / 32.3)
-rc_mode cqp, P-frame QP 0 61.1 / 55.3 / 53.1 61.1 / 55.3 / 49.0
-rc_mode cqp, P-frame QP 10 53.7 / 47.6 / 44.8 53.7 / 42.1 / 38.3
-rc_mode cqp, P-frame QP 22 47.3 / 42.0 / 40.1 47.3 / 36.2 / 34.1
-rc_mode cqp, P-frame QP 30 45.1 / 44.2 / 45.1 45.1 / 43.0 / 45.1 (slight)
-rc_mode cqp, P-frame QP 40 flat 45.1 / 45.5 / 45.1 flat

Notes on these results:

  • Forcing level 5.1 instead of the 6.1 that FFmpeg picked by default gave identical PSNR.
  • -rc_mode driver did not drift. However, the driver’s own rate control produced a QP-0 I-frame followed by roughly 3.6 KB P-frames (essentially all skip), so there was no residual coding that could drift.

Not affected

These were measured with the synthetic image unless noted. All plateau.

configuration result
hevc_nvenc (NVENC API), same GPU and driver, 3840x2160 flat
hevc_nvenc with -split_encode_mode 2 flat; output identical to the default
h264_vulkan, same GPU and driver, 3840x2160 flat
h264_nvenc and av1_nvenc (real capture) flat
hevc_vulkan on Mesa RADV (AMD VCN 4), same FFmpeg and command, 3840x2160 flat
hevc_vulkan on NVIDIA at 1280x720, 1920x1080 (80 and 20 Mbps), 2560x1440, 3840x1080, 1920x2160 flat (synthetic image; 720p and 1080p also with the real capture)

So on this driver the problem needs both the full 3840 width and the full 2160 height. Halving either dimension makes it disappear.

Notes and hypotheses (unverified)

  • The affected region is exactly the first 64 CTBs in raster order (2048 luma pixels), and only at 3840x2160. To me this looks like something internal to the driver or firmware that only engages at this picture size, for example an internal split or partition of the frame, or a line buffer sized at 2048, rather than a bitstream-syntax issue.
  • H.264 via Vulkan is fine on the same GPU, and the HEVC error covers whole CTBs uniformly, not just the picture-edge rows. This suggests chroma SAO parameters or chroma reconstruction for those CTBs not being applied identically in the encoder’s reference. For example, the reference might be stored before or without SAO for that region while the bitstream signals SAO.
  • I could not test with SAO disabled, because FFmpeg’s hevc_vulkan has no option for it. If the driver has an internal way to turn SAO off for Vulkan encode sessions, that would be the quickest way to confirm or rule this out.
  • Workarounds on the application side: periodic IDR or intra refresh, using H.264, or using the NVENC API instead of Vulkan Video.

Attachments

  • hevc-vulkan-chroma-drift-repro.sh: self-contained repro script below (needs only FFmpeg with Vulkan)
  • nvidia-bug-report.log.gz: from sudo nvidia-bug-report.sh
#!/usr/bin/env bash
# Repro: Vulkan Video H.265 encode on the NVIDIA Linux driver - chroma drift (encoder/decoder
# reference mismatch) in the first 64 CTUs of the top CTU row at 3840x2160.
#
# What it does:
#   1. Synthesizes a deterministic 3840x2160 test image (colour gradients + static noise).
#   2. Encodes that one image N times (a perfectly static scene) with FFmpeg's hevc_vulkan:
#      P-frames only, no IDR after frame 0, CBR with a one-frame VBV, as a low-latency game
#      streamer would.
#   3. Decodes with FFmpeg's software HEVC decoder and prints PSNR against the source for the
#      whole frame and for regions of the top 32 luma rows (CTU row 0 with 32x32 CTBs).
#
# Expected: PSNR plateaus once the encoder has converged on the static image (it does for
#           h264_vulkan, hevc_nvenc, and for hevc_vulkan on another vendor's Vulkan driver).
# Actual:   luma plateaus, but U/V PSNR in the left 2048 px of the top 32 px row keeps falling
#           every frame; the rest of the picture is unaffected.
#
# Usage: ./hevc-vulkan-chroma-drift-repro.sh [WIDTH] [HEIGHT] [FRAMES] [ENCODER]
#   defaults: 3840 2160 300 hevc_vulkan   (ENCODER may also be h264_vulkan or hevc_nvenc as controls)
#   env: MBPS=80 (CBR rate)  VK_DEVICE=0 (Vulkan device index)  EXTRA_ENC_OPTS="..." (appended
#        encoder options)  SRC_IMAGE=file.png (use an image instead of the synthetic one)
#        OUT_DIR=./hevc-drift-out
# Requires: ffmpeg with Vulkan and hevc_vulkan (tested with FFmpeg 9.0.1). Runs at real time
#           (-readrate 1), so 300 frames take ~5 s.
set -euo pipefail

W=${1:-3840}; H=${2:-2160}; N=${3:-300}; ENC=${4:-hevc_vulkan}
FPS=60
MBPS=${MBPS:-80}
BUFSIZE=$(( MBPS * 1000000 / FPS ))   # one-frame VBV
DIR=${OUT_DIR:-./hevc-drift-out}
mkdir -p "$DIR"; cd "$DIR"

# 1) Test image.
if [ -n "${SRC_IMAGE:-}" ]; then
  ffmpeg -hide_banner -loglevel error -y -i "$SRC_IMAGE" -vf "scale=${W}:${H},format=rgb24" -frames:v 1 still.png
else
  ffmpeg -hide_banner -loglevel error -y \
    -f lavfi -i "gradients=s=${W}x${H}:n=6:seed=7:speed=0:type=linear:c0=red:c1=lime:c2=blue:c3=yellow:c4=magenta:c5=cyan,format=rgb24,noise=alls=24:allf=0:all_seed=12345" \
    -frames:v 1 still.png
fi

# 2) Encode the still N times.
case "$ENC" in
  *_vulkan)
    HW=(-init_hw_device "vulkan=vk:${VK_DEVICE:-0}" -filter_hw_device vk)
    VF="scale=out_color_matrix=bt709:out_range=pc,format=nv12,hwupload"
    EOPTS=(-rc_mode cbr -tune ll -usage stream -content rendered -async_depth 1) ;;
  *_nvenc)
    HW=()
    VF="scale=out_color_matrix=bt709:out_range=pc,format=nv12"
    EOPTS=(-rc cbr -tune ll -preset p1 -delay 0) ;;
  *) echo "unsupported encoder $ENC" >&2; exit 2 ;;
esac
# shellcheck disable=SC2086
ffmpeg -hide_banner -loglevel error -y "${HW[@]}" \
  -readrate 1 -loop 1 -framerate $FPS -i still.png -frames:v "$N" \
  -vf "$VF" -color_range pc -colorspace bt709 \
  -c:v "$ENC" -b:v "${MBPS}M" -maxrate "${MBPS}M" -bufsize "$BUFSIZE" -g 32767 -bf 0 \
  "${EOPTS[@]}" ${EXTRA_ENC_OPTS:-} \
  out.mkv

# 3) Decode with libavcodec (software) and compute per-frame PSNR vs. the source, per region.
REF="scale=out_color_matrix=bt709:out_range=pc,format=yuv420p,trim=end_frame=$N"
psnr() { # $1 = filter applied to both decoded and reference, $2 = stats file
  ffmpeg -hide_banner -loglevel error -y -threads 0 -i out.mkv -loop 1 -framerate $FPS -i still.png \
    -filter_complex "[1]$REF,$1[ref];[0]format=yuv420p,$1[d];[d][ref]psnr=stats_file=$2" \
    -f null - 2>&1 | grep -v 'non monotonically' || true
}
SPLIT=2048; [ "$W" -gt "$SPLIT" ] || SPLIT=$W
psnr "null"                               psnr-full.log
psnr "crop=$SPLIT:32:0:0"                 psnr-top-left.log
[ "$W" -gt "$SPLIT" ] && psnr "crop=iw-$SPLIT:32:$SPLIT:0" psnr-top-right.log
psnr "crop=iw:ih-32:0:32"                 psnr-below.log

row() { [ -s "$1" ] || { printf "%23s" "-"; return; }
  awk -v f="$2" '{for(i=1;i<=NF;i++){split($i,a,":");v[a[1]]=a[2]}
  if(v["n"]==f) printf "%7.2f %7.2f %7.2f", v["psnr_y"], v["psnr_u"], v["psnr_v"]}' "$1"; }
echo "encoder=$ENC ${W}x${H} ${MBPS} Mbps CBR, $N frames. PSNR in dB (Y U V) vs. source, software decode."
printf "%5s | %-23s | %-23s | %-23s | %-23s\n" frame "full frame" "rows 0-31, x<$SPLIT" "rows 0-31, x>=$SPLIT" "rows 32-end"
for f in 2 10 60 120 300 600 1200 "$N"; do
  [ "$f" -le "$N" ] || continue
  printf "%5s | %s | %s | %s | %s\n" "$f" "$(row psnr-full.log "$f")" "$(row psnr-top-left.log "$f")" \
    "$(row psnr-top-right.log "$f")" "$(row psnr-below.log "$f")"
done | awk '!seen[$1]++'

nvidia-bug-report.log.gz (1.2 MB)