🐛 Refuse paravirtual H.264 and HEVC sessions of sizes the host lacks

An arm64 guest's VideoToolbox session of a 4:2:0 H.264, HEVC Main or Main 10
stream whose coded size lies outside the host decoder's own, as HEVC under
NVDEC's least size of 144x144, was started, and its pictures failed in the
host's decoder: NVDEC refuses to make a decoder of that size, and VA-API's
surfaces or context refuse it. A client that allowed software decoding got
failed frames rather than pictures.

For the guest: such a session's dsta is now refused with
kVTVideoDecoderUnsupportedDataFormatErr, its warning naming the stream and the
decoder's sizes, as the x86-64 route refuses it at create (5dfe92be1), and the
guest's VideoToolbox decodes the stream in software. That covers an H.264
stream wider than 4096 on iHD, as 4112x2160: iHD's H.264 config lists
8192x8192 but its surfaces take 4096x4096 at most, so such a session started
and its pictures failed. Streams inside the sizes start as before.

The sizes are each arm's own. On NVDEC, its caps of the codec at 4:2:0 and the
stream's depth: nMinWidth and nMinHeight up to nMaxWidth, nMaxHeight and
nMaxMBCount, the checks its decoder's make runs. On VA-API, the decoder the VA
crate's decoder picks for the stream, whose profile choice the video crate now
exports (h264_decoder_profiles, hevc_main_decoder): from its surfaces' least
size, none where they list none, up to the least of its config's and its
surfaces' largest, and H.264's 65,535 blocks. The range extensions' check takes
that bound too.
This commit is contained in:
Anees Iqbal committed 2026-11-27 15:14:14 -08:00
1 parent f09b4f3116
commit e5b03f2d8b
13 files changed
+451 -47

No files matched your search

@@ -19,10 +19,11 @@
//! AV1's Main profile at 8 and 10 bits, whose samples go to the backend whole, temporal units
//! of OBUs, after the record's `configOBUs` (`av1`), in the profiles and tools the codec's
//! `check_supported` takes, which every arm's decode of a picture checks: a stream of
//! monochrome pictures (a HEIC image's alpha), of deeper samples, or of a chroma format and
//! depth the arm declines ([`Backend::declines`], from its own query of the host's decoder; a
//! HEIC image's 4:4:4 thumbnail where the arm decodes no 4:4:4) is refused at its start, not
//! at each frame, with a warning that names why, and the stream's
//! monochrome pictures (a HEIC image's alpha), of deeper samples, or of a chroma format, depth
//! or coded size the arm declines ([`Backend::declines`], from its own query of the host's
//! decoder; a HEIC image's 4:4:4 thumbnail where the arm decodes no 4:4:4, a stream smaller
//! than the decoder's least size) is refused at its start, not at each frame, with a warning
//! that names why, and the stream's
//! profile, chroma format, bit depths and size ([`Undecoded`]). A started session sends `Dpba`,
//! the attributes the guest's output buffers are to have: the two-plane CoreVideo format of its
//! chroma, depth and range that the guest's own software decoder lands the stream in
+4
View File
@@ -18,6 +18,10 @@ pub use va::{
read_back_by, rt_format_names,
};
/// What the paravirtual route checks a stream's start against: the profiles a decoder of it
/// decodes on.
pub use va::{h264_decoder_profiles, hevc_main_decoder};
/// A pool's surface on Windows, a shared Direct3D 12 texture, which a frame names
/// (`Frame::texture`).
#[cfg(windows)]
+2 -2
View File
@@ -76,8 +76,8 @@ pub use encoder::{
};
pub use export::{ExportedPlane, SurfaceExport};
pub use frame::{Frame, FrameHold, GuestWrites, PlaneRows, ReadBack};
pub use h264::{H264_MAX_MACROBLOCKS, H264Decoder};
pub use hevc::{HevcDecoder, range_extensions_decoder};
pub use h264::{H264_MAX_MACROBLOCKS, H264Decoder, decoder_profiles as h264_decoder_profiles};
pub use hevc::{HevcDecoder, main_decoder as hevc_main_decoder, range_extensions_decoder};
pub use import_check::{ImportWrite, ImportWrites};
pub use libva::LoadError;
pub use readback::{ReadbackTimes, ReadbackWay, read_back_by};
+8 -7
View File
@@ -216,11 +216,12 @@ impl VaH264 {
}
}
/// The VA profiles that decode `sps`'s stream, most constrained first:
/// Baseline streams (with FMO refused and redundant slices dropped) are
/// Constrained Baseline's subset of Main.
fn profile_candidates(sps: &Sps) -> &'static [Profile] {
match sps.profile_idc {
/// The VA profiles that decode a stream of `profile_idc`, most constrained
/// first, of which the decoder decodes on the first the driver lists with
/// 4:2:0 render targets: Baseline streams (with FMO refused and redundant
/// slices dropped) are Constrained Baseline's subset of Main.
pub fn decoder_profiles(profile_idc: u8) -> &'static [Profile] {
match profile_idc {
66 => &[
Profile::H264_CONSTRAINED_BASELINE,
Profile::H264_MAIN,
@@ -243,7 +244,7 @@ fn select_profile(display: &Display, sps: &Sps) -> Result<Profile, Error> {
{H264_MAX_MACROBLOCKS} the drivers decode"
)));
}
for &profile in profile_candidates(sps) {
for &profile in decoder_profiles(sps.profile_idc) {
if !display.supports(profile, Entrypoint::VLD) {
continue;
}
@@ -271,7 +272,7 @@ fn select_profile(display: &Display, sps: &Sps) -> Result<Profile, Error> {
Err(Error::Unsupported(format!(
"H.264 profile_idc {} (no VA profile of {:?})",
sps.profile_idc,
profile_candidates(sps)
decoder_profiles(sps.profile_idc)
.iter()
.filter_map(|p| p.name())
.collect::<Vec<_>>()
+25 -7
View File
@@ -249,13 +249,13 @@ impl VaHevc {
/// formats.
fn profile_for(sps: &Sps, range_extensions: bool) -> Result<(Profile, SurfaceFormat), Error> {
if !hevc::is_range_extensions(sps) {
return match (sps.chroma_format_idc, sps.bit_depth_luma_minus8) {
(1, 0) => Ok((Profile::HEVC_MAIN, SurfaceFormat::Nv12)),
(1, 2) => Ok((Profile::HEVC_MAIN10, SurfaceFormat::P010)),
_ => Err(Error::Unsupported(
"HEVC Main: VA-API decodes 4:2:0 at 8 and 10 bits".into(),
)),
};
let bits = sps.bit_depth_luma_minus8.saturating_add(8);
return (sps.chroma_format_idc == 1)
.then(|| main_format(bits))
.flatten()
.ok_or_else(|| {
Error::Unsupported("HEVC Main: VA-API decodes 4:2:0 at 8 and 10 bits".into())
});
}
if !range_extensions {
return Err(Error::Unsupported(
@@ -294,6 +294,24 @@ fn range_extensions_format(chroma_format_idc: u8, bits: u8) -> Option<(Profile,
})
}
/// The profile and surface format of a 4:2:0 stream of Main or Main 10 at
/// `bits`: Main at 8 bits into NV12, Main 10 at 10 into P010.
fn main_format(bits: u8) -> Option<(Profile, SurfaceFormat)> {
match bits {
8 => Some((Profile::HEVC_MAIN, SurfaceFormat::Nv12)),
10 => Some((Profile::HEVC_MAIN10, SurfaceFormat::P010)),
_ => None,
}
}
/// What a 4:2:0 stream of Main or Main 10 at `bits` decodes on, for a caller that checks the
/// driver's answers for it: the profile and the render-target format (a `VA_RT_FORMAT_*` bit)
/// its config is made with; `None` for a depth the decoder takes none of.
pub fn main_decoder(bits: u8) -> Option<(Profile, u32)> {
let (profile, format) = main_format(bits)?;
Some((profile, format.rt_format()))
}
/// What a range extensions stream of `chroma_format_idc` at `bits` decodes on, for a caller that
/// checks the driver's answers for it: the profile, the render-target format (a `VA_RT_FORMAT_*`
/// bit) its config is made with, and the surfaces' FOURCC; `None` for a chroma format or depth
+18 -6
View File
@@ -55,7 +55,10 @@
//! GPU, one `cuMemcpy2D` a plane into the view of its pages registered with CUDA, as into an
//! output's pages above, else read back and copied by the CPU, each reason logged once a
//! decoder. So every decode codec of the caps has one, and the device offers `VT_MESSAGES`
//! where NVDEC decodes H.264 or HEVC.
//! where NVDEC decodes H.264 or HEVC. A session of a stream whose coded size lies outside
//! NVDEC's caps of its codec at its chroma format and depth (`nMinWidth` by `nMinHeight` up to
//! `nMaxWidth` by `nMaxHeight` and `nMaxMBCount`, as the decoder's make checks them) is refused
//! at its start ([`declines`]), and the guest decodes the stream in software.
//! - **VP9** decodes there alone, profile 0 where NVDEC decodes VP9 at 8 bits and profile 2
//! where it does at 10 ([`vp9_caps`]), each sample a frame or a superframe whole, and lands as
//! H.264's and HEVC's 4:2:0 pictures do. Its caps entry, codec 3, is skipped by an x86
@@ -492,17 +495,26 @@ type CapsOf<'a> = &'a dyn Fn(NvdecCodec, ChromaFormat, u32) -> Result<DecodeCapa
/// Why NVDEC's decoders take none of `stream`'s pictures, a stream of `codec` the codec module
/// takes, by what `caps` answers: an HEVC stream of the range extensions as
/// [`declines_range_extensions`] says; any other but 4:2:0's; `None` where they decode it.
/// [`declines_range_extensions`] says; a 4:2:0 stream of H.264, or of HEVC's Main or Main 10,
/// where the caps of its codec at 4:2:0 and its depth do not say NVDEC decodes it, at its size
/// among them ([`declines_by`]); any other; `None` where they decode it.
fn declines(caps: CapsOf<'_>, codec: u32, stream: &Stream) -> Option<String> {
if codec == RGFX_VIDEO_CODEC_HEVC && stream.range_extensions {
return declines_range_extensions(caps, stream);
}
(stream.chroma_format_idc != 1 || stream.range_extensions).then(|| {
format!(
if stream.chroma_format_idc != 1 || stream.range_extensions {
return Some(format!(
"{NAME}'s decoders land 4:2:0 pictures, and HEVC's range extensions where NVDEC \
decodes them, alone"
)
})
));
}
let (nvdec, what) = match codec {
RGFX_VIDEO_CODEC_H264 => (NvdecCodec::H264, "H.264"),
RGFX_VIDEO_CODEC_HEVC => (NvdecCodec::Hevc, "HEVC 4:2:0"),
other => return Some(format!("{NAME} decodes no codec {other} here")),
};
let (chroma, bits) = (ChromaFormat::Yuv420, u32::from(stream.luma_bits));
declines_by(caps(nvdec, chroma, bits), what, chroma, bits, stream)
}
/// Why NVDEC's decoders take none of `stream`'s pictures, an HEVC stream of the range
@@ -873,3 +873,138 @@ fn nvidia_errors_reach_videotoolbox_as_their_kind() {
VideoError::Malfunction("every decode surface is held".to_owned())
);
}
/// What NVDEC answers of `codec` at `chroma` and `bits`: decoded into NV12 and P016, from `min`
/// up to `max` and the blocks `max` holds.
fn nvdec_answer(
codec: NvdecCodec,
chroma: ChromaFormat,
bits: u32,
min: (u32, u32),
max: (u32, u32),
) -> DecodeCapabilities {
DecodeCapabilities {
codec,
chroma,
bit_depth: bits,
supported: true,
engines: 1,
output_formats: vec![SurfaceFormat::Nv12, SurfaceFormat::P016],
max_width: max.0,
max_height: max.1,
max_macroblocks: (max.0 / 16) * (max.1 / 16),
min_width: min.0,
min_height: min.1,
}
}
/// A 4:2:0 stream of H.264, or of HEVC's Main or Main 10, is declined at its session's start
/// where NVDEC's caps of its codec at its depth leave its size out (each side from the least up
/// to the largest, and the blocks), or say NVDEC does not decode it, naming why; and taken within
/// them. The caps are the RTX 5080 Laptop GPU's least sizes, H.264 from 48x64 and HEVC from
/// 144x144 (`docs/video/bugs.md`, D14)
#[test]
fn a_4_2_0_stream_outside_nvdecs_caps_is_declined_at_its_start() {
use reims_vgpu_video::paravirt::Codec as StreamCodec;
type Answer = Result<DecodeCapabilities, String>;
let (h264, hevc) = (RGFX_VIDEO_CODEC_H264, RGFX_VIDEO_CODEC_HEVC);
// The device's codec and a 4:2:0 stream of it.
let stream = |codec: u32, luma_bits: u8, width: u32, height: u32| {
let (of, profile) = if codec == h264 {
(StreamCodec::H264, 100)
} else {
(StreamCodec::Hevc, 1)
};
let stream = Stream {
codec: of,
profile,
chroma_format_idc: 1,
luma_bits,
chroma_bits: luma_bits,
width,
height,
range_extensions: false,
};
(codec, stream)
};
let caps = |codec: NvdecCodec, chroma: ChromaFormat, bits: u32| -> Answer {
Ok(match codec {
NvdecCodec::H264 => nvdec_answer(codec, chroma, bits, (48, 64), (4096, 4096)),
_ => nvdec_answer(codec, chroma, bits, (144, 144), (8192, 8192)),
})
};
for (codec, taken) in [
stream(h264, 8, 48, 64),
stream(h264, 8, 1920, 1088),
stream(h264, 8, 4096, 4096),
stream(hevc, 8, 144, 144),
stream(hevc, 8, 8192, 8192),
stream(hevc, 10, 144, 144),
stream(hevc, 10, 3840, 2160),
] {
assert_eq!(declines(&caps, codec, &taken), None, "{taken:?}");
}
for ((codec, declined), why) in [
(
stream(h264, 8, 32, 64),
"NVDEC decodes H.264 from 48x64, not 32x64",
),
(
stream(h264, 8, 48, 48),
"NVDEC decodes H.264 from 48x64, not 48x48",
),
(
stream(h264, 8, 4112, 64),
"NVDEC decodes H.264 up to 4096x4096 (65536 macroblocks), not 4112x64",
),
(
stream(hevc, 8, 128, 128),
"NVDEC decodes HEVC 4:2:0 from 144x144, not 128x128",
),
(
stream(hevc, 10, 144, 136),
"NVDEC decodes HEVC 4:2:0 from 144x144, not 144x136",
),
(
stream(hevc, 8, 8200, 144),
"NVDEC decodes HEVC 4:2:0 up to 8192x8192 (262144 macroblocks), not 8200x144",
),
(
stream(hevc, 10, 144, 8200),
"NVDEC decodes HEVC 4:2:0 up to 8192x8192 (262144 macroblocks), not 144x8200",
),
] {
assert_eq!(declines(&caps, codec, &declined).as_deref(), Some(why));
}
let blocks = |codec: NvdecCodec, chroma: ChromaFormat, bits: u32| -> Answer {
Ok(DecodeCapabilities {
max_macroblocks: 8160,
..nvdec_answer(codec, chroma, bits, (144, 144), (4096, 4096))
})
};
let (codec, fits) = stream(hevc, 8, 1920, 1080);
assert_eq!(declines(&blocks, codec, &fits), None);
let (codec, wider) = stream(hevc, 8, 2048, 1080);
assert_eq!(
declines(&blocks, codec, &wider).as_deref(),
Some("NVDEC decodes HEVC 4:2:0 up to 4096x4096 (8160 macroblocks), not 2048x1080")
);
let eight_bits_alone = |codec: NvdecCodec, chroma: ChromaFormat, bits: u32| -> Answer {
Ok(DecodeCapabilities {
supported: bits == 8,
..nvdec_answer(codec, chroma, bits, (144, 144), (8192, 8192))
})
};
let (codec, ten_bits) = stream(hevc, 10, 1920, 1080);
assert_eq!(
declines(&eight_bits_alone, codec, &ten_bits).as_deref(),
Some("NVDEC does not decode HEVC 4:2:0 at 10 bits")
);
let refused =
|_: NvdecCodec, _: ChromaFormat, _: u32| -> Answer { Err("no CUDA device".to_owned()) };
let (codec, any) = stream(h264, 8, 1920, 1088);
assert_eq!(
declines(&refused, codec, &any).as_deref(),
Some("NVDEC's caps of H.264 at 8 bits: no CUDA device")
);
}
+75 -13
View File
@@ -79,7 +79,11 @@
//! - **VideoToolbox's paravirtual decoders** (`VaGuestDecoder`, `super::vt`): an arm64 guest's
//! decode lands in the IOSurface its kext lent, written there by the driver's video processing
//! (`Frame::write_to_guest`, the first way above) where the import check takes the surface's
//! layout and memory, else read back and copied by the CPU into the surface's pages. An HEVC
//! layout and memory, else read back and copied by the CPU into the surface's pages. A 4:2:0
//! stream of H.264, or of HEVC's Main or Main 10, decodes where the driver's decoder the VA
//! crate's decoder picks for it takes its coded size (`declines_4_2_0`, from the driver's own
//! answers: the least size its surfaces list, the largest its config and its surfaces list);
//! elsewhere its session is refused at its start, and the guest decodes it in software. An HEVC
//! stream of the range extensions decodes where the driver's decoder of its chroma format and
//! depth takes it (`declines_range_extensions`, from the driver's own answers: the profile, its
//! render-target format, its surfaces' FOURCC and sizes; the VA crate's
@@ -140,6 +144,7 @@ use reims_vgpu_video::vaapi::{
use reims_vgpu_video::vaapi::{SurfaceCapabilities, range_extensions_decoder, rt_format_names};
#[cfg(unix)]
use reims_vgpu_video::vaapi::{TARGET_ALIGNMENT, TargetChecks, TargetPlane, TargetShape};
use reims_vgpu_video::vaapi::{h264_decoder_profiles, hevc_main_decoder};
#[cfg(unix)]
use reims_vgpu_vulkan::core::num::ToU64 as _;
use reims_vgpu_vulkan::core::num::ToUsize as _;
@@ -670,35 +675,92 @@ impl<P: Platform> GraphicsVideo<P> for VaapiVideo<P> {
/// Why the driver's decoders among `configs` take none of `stream`'s pictures, a stream of
/// `codec` the codec module takes: an HEVC stream of the range extensions as
/// [`declines_range_extensions`] says; any other but 4:2:0's; `None` where they decode it.
/// [`declines_range_extensions`] says; a 4:2:0 stream of H.264, or of HEVC's Main or Main 10,
/// as [`declines_4_2_0`] says; any other; `None` where they decode it.
fn declines(configs: &[ConfigCapabilities], codec: u32, stream: &Stream) -> Option<String> {
if codec == RGFX_VIDEO_CODEC_HEVC && stream.range_extensions {
return declines_range_extensions(configs, stream);
}
(stream.chroma_format_idc != 1 || stream.range_extensions).then(|| {
format!(
if stream.chroma_format_idc != 1 || stream.range_extensions {
return Some(format!(
"{NAME}'s decoders land 4:2:0 pictures, and HEVC's range extensions where the \
driver decodes them, alone"
)
})
));
}
declines_4_2_0(configs, codec, stream)
}
/// Why the driver decodes none of a 4:2:0 `stream`'s pictures, of H.264 or of HEVC's Main or
/// Main 10, `None` where it decodes them: on the decoder among `configs` the VA crate's decoder
/// picks for it, the first of its profiles (`h264_decoder_profiles`, `hevc_main_decoder`) the
/// driver lists with its render targets, within its sizes ([`sizes_of`]; and H.264's at most
/// `H264_MAX_MACROBLOCKS`, past which the VA crate's decoder refuses it).
fn declines_4_2_0(configs: &[ConfigCapabilities], codec: u32, stream: &Stream) -> Option<String> {
let hevc = hevc_main_decoder(stream.luma_bits);
let (profiles, rt_format, max_macroblocks) = match (codec, &hevc) {
(RGFX_VIDEO_CODEC_H264, _) => (
h264_decoder_profiles(stream.profile),
RT_YUV420,
Some(H264_MAX_MACROBLOCKS),
),
(RGFX_VIDEO_CODEC_HEVC, Some((profile, rt_format))) => {
(std::slice::from_ref(profile), *rt_format, None)
}
(RGFX_VIDEO_CODEC_HEVC, None) => {
return Some(format!(
"{NAME} decodes HEVC Main and Main 10 at 8 and 10 bits, not {}",
stream.luma_bits
));
}
(other, _) => return Some(format!("{NAME} decodes no codec {other} here")),
};
let decoder = profiles.iter().find_map(|&profile| {
configs.iter().find(|config| {
config.profile == profile
&& (config.rt_formats).is_none_or(|formats| formats & rt_format != 0)
})
});
let Some(config) = decoder else {
let names: Vec<&str> = profiles
.iter()
.filter_map(|profile| profile.name())
.collect();
return Some(format!(
"{NAME}: the driver has no {} decoder of {} render targets",
names.join(" or "),
rt_format_names(rt_format).join(", ")
));
};
let name = config.profile.name().unwrap_or("its");
let sizes = DecodeSizes {
max_macroblocks,
..sizes_of(config, config.surfaces.as_ref().ok())
};
sizes.declines(
&format!("{NAME} decodes {name}"),
stream.width,
stream.height,
)
}
/// The sizes `config`'s decoder takes, of `surfaces`: from the least its surfaces list (0 where
/// they list none) up to the largest the config lists, else its surfaces.
/// they list none) up to the least of the largest the config and its surfaces list, either of
/// which refuses a picture past it (iHD's H.264 config lists 8192x8192, and its surfaces 4096x4096:
/// `docs/video/vaapi.md`, "The H.264 decoder").
fn sizes_of(config: &ConfigCapabilities, surfaces: Option<&SurfaceCapabilities>) -> DecodeSizes {
let listed = |of: fn(&SurfaceCapabilities) -> Option<u32>| surfaces.and_then(of);
let least = |a: Option<u32>, b: Option<u32>| match (a, b) {
(Some(a), Some(b)) => a.min(b),
(a, b) => a.or(b).unwrap_or(u32::MAX),
};
DecodeSizes {
min: (
listed(|s| s.min_width).unwrap_or(0),
listed(|s| s.min_height).unwrap_or(0),
),
max: (
(config.max_width)
.or(listed(|s| s.max_width))
.unwrap_or(u32::MAX),
(config.max_height)
.or(listed(|s| s.max_height))
.unwrap_or(u32::MAX),
least(config.max_width, listed(|s| s.max_width)),
least(config.max_height, listed(|s| s.max_height)),
),
max_macroblocks: None,
}
@@ -287,6 +287,130 @@ fn an_hevc_range_extensions_stream_decodes_on_its_profiles_decoder_of_its_surfac
);
}
/// A 4:2:0 stream of H.264, or of HEVC's Main or Main 10, is declined at its session's start
/// where the driver's decoder of it, the first of its profiles the driver lists with its render
/// targets, leaves its size out (from the least its surfaces list, none where they list none, up
/// to the least of the largest its config and its surfaces list, and H.264's 65,535 blocks), or
/// where the driver lists none, naming why; and taken within them
#[test]
fn a_4_2_0_stream_outside_the_drivers_sizes_is_declined_at_its_start() {
use reims_vgpu_video::paravirt::Codec as StreamCodec;
let (h264, hevc) = (RGFX_VIDEO_CODEC_H264, RGFX_VIDEO_CODEC_HEVC);
// The device's codec and a 4:2:0 stream of it, of H.264's `profile_idc` or at HEVC's depth.
let stream = |codec: u32, profile_or_bits: u8, width: u32, height: u32| {
let (of, profile, bits) = if codec == h264 {
(StreamCodec::H264, profile_or_bits, 8)
} else {
(
StreamCodec::Hevc,
1 + u8::from(profile_or_bits == 10),
profile_or_bits,
)
};
let stream = Stream {
codec: of,
profile,
chroma_format_idc: 1,
luma_bits: bits,
chroma_bits: bits,
width,
height,
range_extensions: false,
};
(codec, stream)
};
let configs = [
config(Profile::H264_MAIN, RT_YUV420, (4096, 4096), Some((64, 64))),
config(Profile::H264_HIGH, RT_YUV420, (4096, 2304), None),
config(
Profile::HEVC_MAIN,
RT_YUV420,
(8192, 8192),
Some((128, 128)),
),
config(
Profile::HEVC_MAIN10,
RT_YUV420 | RT_YUV420_10,
(8192, 4352),
None,
),
];
for (codec, taken) in [
stream(h264, 77, 64, 64),
stream(h264, 77, 4096, 4080),
stream(h264, 66, 64, 64),
stream(h264, 100, 16, 16),
stream(h264, 100, 3840, 2160),
stream(hevc, 8, 128, 128),
stream(hevc, 8, 8192, 8192),
stream(hevc, 10, 8, 8),
stream(hevc, 10, 8192, 4352),
] {
assert_eq!(declines(&configs, codec, &taken), None, "{taken:?}");
}
for ((codec, declined), why) in [
(
stream(h264, 77, 48, 64),
"VA-API decodes H264Main from 64x64, not 48x64",
),
(
stream(h264, 66, 64, 48),
"VA-API decodes H264Main from 64x64, not 64x48",
),
(
stream(h264, 77, 4096, 4096),
"VA-API decodes H264Main up to 4096x4096 (65535 macroblocks), not 4096x4096",
),
(
stream(h264, 100, 4096, 2320),
"VA-API decodes H264High up to 4096x2304 (65535 macroblocks), not 4096x2320",
),
(
stream(hevc, 8, 120, 128),
"VA-API decodes HEVCMain from 128x128, not 120x128",
),
(
stream(hevc, 8, 8200, 128),
"VA-API decodes HEVCMain up to 8192x8192, not 8200x128",
),
(
stream(hevc, 10, 1920, 4360),
"VA-API decodes HEVCMain10 up to 8192x4352, not 1920x4360",
),
] {
assert_eq!(declines(&configs, codec, &declined).as_deref(), Some(why));
}
let eight_bits_alone = [
config(Profile::H264_HIGH, RT_YUV420, (4096, 2304), None),
config(Profile::HEVC_MAIN10, RT_YUV420, (8192, 4352), None),
];
let (codec, ten_bits) = stream(hevc, 10, 1920, 1080);
assert_eq!(
declines(&eight_bits_alone, codec, &ten_bits).as_deref(),
Some("VA-API: the driver has no HEVCMain10 decoder of YUV420_10 render targets")
);
// iHD's H.264 config lists 8192x8192, and its surfaces 4096x4096.
let mut ihd = config(Profile::H264_HIGH, RT_YUV420, (8192, 8192), Some((16, 16)));
if let Ok(surfaces) = ihd.surfaces.as_mut() {
(surfaces.max_width, surfaces.max_height) = (Some(4096), Some(4096));
}
let (codec, wide) = stream(h264, 100, 4112, 2160);
assert_eq!(
declines(std::slice::from_ref(&ihd), codec, &wide).as_deref(),
Some("VA-API decodes H264High up to 4096x4096 (65535 macroblocks), not 4112x2160")
);
let (codec, uhd) = stream(h264, 100, 4096, 2160);
assert_eq!(declines(std::slice::from_ref(&ihd), codec, &uhd), None);
let (codec, baseline) = stream(h264, 66, 1920, 1088);
assert_eq!(declines(&eight_bits_alone, codec, &baseline), None);
let (codec, main) = stream(h264, 77, 1920, 1088);
assert_eq!(declines(&eight_bits_alone, codec, &main), None);
assert_eq!(
declines(&[], codec, &main).as_deref(),
Some("VA-API: the driver has no H264Main or H264High decoder of YUV420 render targets")
);
}
/// The layout is granularity [2, 2] at the largest alignment the import check found for the
/// codec's formats, and zero where it found none
#[test]
+12 -4
View File
@@ -1876,7 +1876,13 @@ Stages:
session's `dsta` on one is refused with
`kVTVideoDecoderUnsupportedDataFormatErr`: the arms decode 4:2:0
pictures, of 8 bits, or 10 in HEVC, in the profiles and tools the
codec's `check_supported` takes, and NVDEC and VA-API also HEVC's
codec's `check_supported` takes, at the coded sizes the arm's own
query of its decoder lists (NVDEC's caps of the codec at the
stream's chroma format and depth; the VA driver's decoder of the
stream's profile, from its surfaces' least size up to the least of
its config's and its surfaces' largest;
[devices.md](../video/devices.md), "A stream outside the host
decoder's sizes"), and NVDEC and VA-API also HEVC's
range extensions, 4:2:0, 4:2:2 and 4:4:4 at 8, 10 and 12 bits,
where the arm's own query lists a decoder of the stream: NVDEC's caps
for its chroma format, depth and size, 4:2:2 aside, or the VA
@@ -1900,9 +1906,11 @@ Stages:
guests"). A
stream the codec refuses (monochrome, a HEIC image's alpha item, a
depth past 12 bits, screen content coding), or one the arm declines
(a range extensions stream on a VA driver without its decoder,
radeonsi's, or on an NVIDIA GPU whose caps lack it, and HEVC 4:2:2
on NVDEC: the arm's `guest_declines`), is then refused at
(a stream of a coded size outside its decoder's, as HEVC under
NVDEC's 144x144; a range extensions stream on a VA driver without
its decoder, radeonsi's, or on an NVIDIA GPU whose caps lack it,
and HEVC 4:2:2 on NVDEC: the arm's `guest_declines`), is then
refused at
the session's start, not at
each tile or frame, and every tile a session takes lands in the
format its `TDrs` names. The refusal's warning names the stream and
+1 -1
View File
@@ -197,6 +197,6 @@ Bugs in drivers, libraries and tools that our code or our checks work around.
- **D10. No tool copies a test VM between hosts.** The first VM on the NVIDIA host was made from a Radeon host's VM by hand: a snapshot, its free space zeroed in a scratch VM, `qemu-img convert`, and a copy over the network. A tool that crosses hosts waits until a second cross-host VM is wanted, since the next VM on that host is better copied from the one there.
- **D12. NVENC runs without lookahead.** The `nvidia` module's encoder turns it off in every preset's configuration (`crates/reims-vgpu-video/src/nvidia/nvenc/encoder.rs`), since with it on frames are lost (U6). P6 and P7 lose the quality lookahead brings, unmeasured.
- **D14. NVIDIA's smallest frames.** NVDEC decodes HEVC from 144x144 and H.264 from 48x64; NVENC encodes H.264 from 145x49 and HEVC from 129x33. Each is the driver's answer (**measured** with `nvidia-probe`, RTX 5080 Laptop GPU, 2026-10-24), and the graphics device's caps give the guest the decoder's.
- **D14. NVIDIA's smallest frames.** NVDEC decodes HEVC from 144x144 and H.264 from 48x64; NVENC encodes H.264 from 145x49 and HEVC from 129x33. Each is the driver's answer (**measured** with `nvidia-probe`, RTX 5080 Laptop GPU, 2026-10-24), and the graphics device's caps give the guest the decoder's. An arm64 guest's VideoToolbox session of a stream smaller than the decoder's is refused at its start, and the guest decodes it in software ([devices.md](devices.md), "A stream outside the host decoder's sizes").
- **D25. The graphics device's video driver cannot report a host's H.264 decode failure.** The guest lane's video driver (`guest/bundle/src/RgfxVideoDriver.cpp`, docs/graphics-kext/design.md, "A decode the driver cannot complete is a decode error") fails the schedule of an HEVC picture the host failed, as the schedule waits for the host's verdict on it, and VideoToolbox reports `kVTVideoDecoderMalfunctionErr` (-12911) from that picture on (`waitsForHost`, `guest/bundle/src/RgfxVideoStatus.hpp`). AppleGVA's H.264 decoder reports no failure at all: a failed schedule (5, 1 or 7, once or for every schedule after), the query's status 0, 3 or 4, its field_08 or field_14 set, and a failed query call each leave every frame decoded, and a picture whose schedule failed is not decoded (**measured** on the guest with the RTX 5080, 2026-11-07, every picture failed on the host). AppleGVA's code on macOS 26.7.1 holds no other way (**read** 2026-11-08): its decode flow takes every query for the command's completion, reading neither the status nor the error word, and reports a failure only through a failed batch schedule, while the H.264 pipelines schedule their commands one at a time and keep no decode's result. So an H.264 schedule waits for no verdict, and an H.264 picture the host fails after it was sent reaches the guest as decoded. What the driver can tell before a picture it refuses at its context's create instead: a coded size outside the host's H.264 decode entry (`sizeTaken`, `CreateContexts`), and VideoToolbox decodes the stream in software (**measured** in the guest on a Radeon 780M, 2026-11-08: a 4096x4096 stream, past the entry's 4096x4080 (U28), failed its hardware session's create and decoded right in software; answered 4096x4096, it was taken, and its frames reached the client undecoded). The session's create also fails, in the guest as on the real Macs, for 4:2:2, 4:4:4, monochrome and lossless streams, for 8192x4320, and for interlaced ones (T3); VideoToolbox's software decoder then decodes 8192x4320 and JM's interlaced streams right, x264's interlaced ones wrongly, and fails on the rest. AppleGVA hands the driver no SPS or PPS before the first picture, so what the host refuses from them or from the slices still reaches the guest undecoded: High 10, slice groups (FMO), data partitioning, and SP and SI slices. The guest's frames of them are the real Macs': their hardware decodes those wrongly too, on the Radeon Pro 5300M and the UHD 630 alike, and mostly with no error: every frame of High 10 wrong, FMO's wrong (a box-out stream's with errors), a data-partitioned stream's first frame and then none, and an Extended stream with SP slices wrong from its first SP picture (**measured** on macOS 26.7.1, and in the guest with the 5300M's counts, 2026-11-08, streams of JM 19.0 and x264). Left are those, a host's refusal of the picture once it has it (its planes refused), and a decode the hardware failed once it ran, which on NVDEC lands as NVDEC left it, the pictures after it decoded from it, as a Mac's hardware decoder hands such a picture on with no error (**measured** on a MacBook Pro of 2019, macOS 26.7.1, 2026-11-16: an H.264 P picture cut to half its slice, or with 64 bytes of it changed, and those after it came back with status 0, 26.5 to 29.7 dB from the undamaged stream's luma and none all zeros, until the next IDR picture; [nvidia.md](nvidia.md), "A picture NVDEC failed lands as NVDEC left it"). Put off: AppleGVA leaves no answer. To lift it: an H.264 path in AppleGVA that reads a driver's failure, on a release that has one.
- **D26. On the rt platform on Windows, a guest texture over a video plane in another format is a copy of the plane.** A video cache's planes lie over Direct3D 11 textures the host's video draws its pictures into, which rt imports with the uses their bind flags give (`RENDER_TARGET | SHADER_RESOURCE`) and no view format but the texture's element format, the plane image's (`R8Unorm`, `RG8Unorm`, `R16Unorm` or `RG16Unorm`) and that one's sRGB sibling (**read**, metal2vulkan-runtime at ec9e2771d0, `d3d11_plane_form`). A guest texture over such a plane in the image's format or its sRGB sibling is a view of the plane. One in any other format of the texel's size, an `R8Uint` over the luma plane say, which Metal makes over a plane of an IOSurface and rt would refuse (`Gap::TextureView`, `SurfacePixelFormat`), takes the storage shape of its extent instead, an image of its own that copies keep current with the plane (rule 1 at the end of each encoder that writes either, and a fill after each picture), and later textures of that extent view that shape too, so the cache's later pictures reach them through its buffer (`crates/reims-vgpu/src/graphics/decode/surface_cache/shapes.rs`, "Plane shapes"). The guest reads the same pixels, at the copies' cost. Counted as `rt-shape-drawn-format-storage-<plane's format>-as-<texture's format>`, the first of each pair logged; `a_texture_over_a_drawn_plane_in_another_format_takes_the_storage_shape` holds it. No boot has counted one yet. Put off: the planner's ruling of 2026-11-23 keeps rt's import exactly the textures' Direct3D 11 description, and the copy costs nothing until a guest asks such a view. To lift it: where boots count such textures, textures whose Direct3D 11 format allows the views guests ask, and rt's import listing them.
+37 -2
View File
@@ -50,8 +50,8 @@ profile of (`guest_encoders` in `graphics/vaapi.rs` and `graphics/nvidia.rs`). S
an arm64 guest decodes H.264, HEVC and VP9 and encodes H.264 and HEVC Main and Main 10 in
hardware; on a Windows host it decodes alone, as the Windows arm answers no encoder. Its decoders
land 4:2:0 pictures, and HEVC's range extensions, 4:2:0, 4:2:2 and 4:4:4 at 8, 10 and 12 bits,
where the arm's own query lists a decoder of the stream (`guest_declines`; "HEVC's range
extensions on arm64 guests", below).
where the arm's own query lists a decoder of the stream at its size (`guest_declines`; "A stream
outside the host decoder's sizes" and "HEVC's range extensions on arm64 guests", below).
VP9 reaches the host by this route alone. Its caps entry (codec 3, `RGFX_VIDEO_CODEC_VP9`) lists
profile 0, into NV12, where the arm decodes VP9 at 8 bits, and profile 2, into P010, where it
@@ -432,6 +432,41 @@ in host bytes, and the session copies it into the cache on a runtime queue. Each
how its pictures landed, and logs the counts at its end ([vaapi.md](vaapi.md), "The
reims-graphics device").
## A stream outside the host decoder's sizes
A host decoder takes pictures from its least size up to its largest, as the arm's own query of it
lists them:
- **NVDEC**: its caps of the stream's codec at its chroma format and depth (`cuvidGetDecoderCaps`),
from `nMinWidth` by `nMinHeight` up to `nMaxWidth` by `nMaxHeight` and `nMaxMBCount` blocks of
16x16, which the decoder's make checks too: on the RTX 5080 Laptop GPU, H.264 from 48x64 and
HEVC from 144x144 ([bugs.md](bugs.md), D14).
- **VA-API**: the driver's decoder the VA crate's decoder picks for the stream, of the first
profile that decodes it the driver lists with its render targets (for H.264, of Constrained
Baseline, Main and High; for HEVC, Main, Main 10 or the range extensions' profile of the
stream's chroma format and depth), from the least size its surfaces list (none, where they list
none) up to the least of the largest its config and its surfaces list (iHD's H.264 config lists
8192x8192, its surfaces 4096x4096), and for H.264 at most the 65,535 blocks the VA crate's
decoder takes.
An x86-64 guest's caps carry the decoder's sizes, and the guest's video driver refuses a session
of a coded size outside them at its create, so VideoToolbox decodes such a stream in software
(`guest/bundle/src/RgfxVideoDriver.cpp`). On an arm64 guest, a VideoToolbox session of an H.264
or HEVC stream whose coded size lies outside them is refused at its `dsta`, its warning naming the
stream and the sizes (`guest_declines` in `graphics/nvidia.rs` and `graphics/vaapi.rs`, through
`graphics/decode_sizes.rs`, as `NVDEC decodes HEVC 4:2:0 from 144x144, not 128x128`), and the
guest's VideoToolbox decodes the stream in software where its client allows it. Before, the
session was made and its pictures failed in the host's decoder. AV1's sessions are checked
against the arm's AV1 decoder the same way ("AV1 on arm64 guests", above).
Measured on an arm64 macOS 26.6.2 guest under TCG on an RTX 3090 host (potluck job m3-max-77509,
2026-11-27), each stream decoded by a session that allows a hardware decoder and requires none:
H.264 at 32x32, HEVC Main at 128x128 and Main 10 at 128x96, each under the 3090's least size (H.264
48x16, HEVC 144x144), were refused at their `dsta` with `NVDEC decodes H.264 from 48x16, not 32x32`
and `NVDEC decodes HEVC 4:2:0 from 144x144, not ...`, and the guest decoded each stream's 30
pictures in software, every one the same as a decode that allows no hardware decoder; H.264 and
HEVC Main at 640x360 decoded in hardware, every picture the same.
## HEVC's range extensions on arm64 guests
VideoToolbox's paravirtual decoders, an arm64 guest's alone, take HEVC's range extensions where
+5 -1
View File
@@ -93,7 +93,11 @@ NVIDIA parser is used: the codec module parses every stream, as for VA-API.
Each has 2 decode engines. NVDEC also lists H.264 at 10 bits and 4:2:2,
and HEVC 4:2:2 and 4:4:4, which the device's caps do not offer; HEVC's
range extensions at 4:2:0 and 4:4:4 are decoded for VideoToolbox's
paravirtual decoders ([devices.md](devices.md)), and its 4:2:2 is not.
paravirtual decoders ([devices.md](devices.md)), and its 4:2:2 is not. A
paravirtual session of a stream outside the sizes of its codec, chroma
format and depth is refused at its start, and the guest decodes it in
software ([devices.md](devices.md), "A stream outside the host decoder's
sizes").
The RTX 3090 (620.70.06, `nvidia-probe`, 2026-11-22) answers HEVC 4:4:4 at
8 bits from 144x144 to 8192x8192, 262,144 macroblocks, into `Yuv444`