diff --git a/crates/reims-vgpu-video/src/vaapi/va.rs b/crates/reims-vgpu-video/src/vaapi/va.rs index cba4fda8c..2be9f0483 100644 --- a/crates/reims-vgpu-video/src/vaapi/va.rs +++ b/crates/reims-vgpu-video/src/vaapi/va.rs @@ -19,6 +19,8 @@ mod caps; mod d3d11; #[cfg(windows)] mod d3d12; +#[cfg(windows)] +mod decode_queue; mod display; mod encoder; mod export; diff --git a/crates/reims-vgpu-video/src/vaapi/va/d3d12.rs b/crates/reims-vgpu-video/src/vaapi/va/d3d12.rs index fca9859a7..9c77c6268 100644 --- a/crates/reims-vgpu-video/src/vaapi/va/d3d12.rs +++ b/crates/reims-vgpu-video/src/vaapi/va/d3d12.rs @@ -287,10 +287,12 @@ impl Drop for Com { } } -/// A Direct3D 12 device on the display's adapter, and its copy queue. +/// A Direct3D 12 device on the display's adapter, and its copy queue. While it lives, the device +/// makes one video decode queue, which every ask for one gets (`super::decode_queue`). pub(crate) struct Device { pub(super) device: Com, copies: Mutex>, + _decode_queue: super::decode_queue::Hold, } /// The objects of the device's copies, made at its first copy. @@ -436,8 +438,10 @@ impl Device { &mut device, ) }; + let device = Com::made("D3D12CreateDevice", result, device)?; Ok(Device { - device: Com::made("D3D12CreateDevice", result, device)?, + _decode_queue: super::decode_queue::Hold::new(&device)?, + device, copies: Mutex::new(None), }) } diff --git a/crates/reims-vgpu-video/src/vaapi/va/decode_queue.rs b/crates/reims-vgpu-video/src/vaapi/va/decode_queue.rs new file mode 100644 index 000000000..69922dd18 --- /dev/null +++ b/crates/reims-vgpu-video/src/vaapi/va/decode_queue.rs @@ -0,0 +1,355 @@ +//! One video decode queue for each Direct3D 12 device, on Windows: every ask on a device of ours +//! for a command queue of type `D3D12_COMMAND_LIST_TYPE_VIDEO_DECODE` gets the same queue. +//! +//! Mesa's VA driver on Direct3D 12 (`vaon12`) makes a video decode queue for each decoder, which +//! is one for each VA context (`d3d12_video_decoder_create_command_objects`, +//! `d3d12_video_dec.cpp`, Mesa 26.2.7). It makes them on the process's one device on the +//! adapter: Mesa asks for it with `ALLOW_RETURNING_EXISTING_DEVICE`, and the device is the same +//! one `super::d3d12` makes the pools' textures on. Intel's Direct3D 12 video driver for the UHD +//! Graphics 630 (`igd12dxva64.dll` 31.0.101.2145, Windows 10.0.26300) decodes wrong pictures on +//! a device's later video decode queue while an earlier one lives. **Measured** on 2026-11-20 +//! (potluck job m3-max-62074, twice), each run decoding a 4K H.264 stream's first 8 access units +//! on a lone VA decoder and comparing them with a decoder's alone: +//! - 8 of 8 pictures wrong when only an idle video decode queue was made on the device first; +//! - 8 of 8 wrong with that queue plus an `ID3D12VideoDecoder` and an `ID3D12VideoDecoderHeap`; +//! - none wrong with the decoder or the heap, or both, made first without a queue; +//! - none wrong with nothing made first. +//! +//! FFmpeg's own D3D12 decoders, each on a queue of its own, show the same: of two or three +//! decoding at once in one process, one decodes right. Its D3D11 decoders and two processes are +//! right (docs/video/bugs.md, U33). So no second video decode queue is made on a device of ours. +//! The vendor does not decide: every device gets the one queue. +//! +//! The device's `ID3D12Device::CreateCommandQueue` (its vtable's slot 8, `d3d12.h`) is replaced +//! by [`create_command_queue`] while a [`Hold`] lives on a device with that vtable. The vtable +//! belongs to the Direct3D 12 runtime's device class, which every device of the process with +//! that vtable shares, so the slot is set for all of them. [`create_command_queue`] calls the +//! slot's own method for every other queue type, and for a device no [`Hold`] holds. For a held +//! device, it makes the device's first video decode queue of a given priority, flags and node +//! mask, keeps it, and answers each later ask with that queue, a reference added for the asker. +//! A queue answered this way lives while any VA context holds it, and while its device's holds +//! live. The module's lock is held across the queue's making, so two first asks on one device +//! make one queue. +//! +//! A device's [`Hold`] is taken in `super::d3d12::Device::new`, which runs before any VA context +//! is made: a pool's textures are made on the device first. When the last hold on a device +//! goes, its kept queues are released. When the last hold on any device with a vtable goes, the +//! slot gets its own method back, unless something else set the slot after us. The method is +//! kept with its vtable for good, so a call that read the slot before it was set back still +//! finds it. + +use std::ffi::c_void; +use std::ptr::null_mut; +use std::sync::atomic::{AtomicUsize, Ordering}; + +use crate::core::sync::Mutex; + +use super::d3d12::{ + Com, CommandQueueDesc, DEVICE_CREATE_COMMAND_QUEUE, Guid, Hresult, IID_ID3D12_COMMAND_QUEUE, + guid, +}; + +/// `D3D12_COMMAND_LIST_TYPE_VIDEO_DECODE`. +const VIDEO_DECODE: u32 = 4; + +/// `IUnknown`'s IID, whose interface is a COM object's identity. +const IID_IUNKNOWN: Guid = guid( + 0x0000_0000, + 0x0000, + 0x0000, + [0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46], +); + +/// `E_FAIL`'s bits. +const E_FAIL: Hresult = 0x8000_4005_u32.cast_signed(); + +/// `PAGE_READWRITE`. +const PAGE_READWRITE: u32 = 0x04; + +#[link(name = "kernel32")] +unsafe extern "system" { + fn VirtualProtect(address: *mut c_void, size: usize, protect: u32, old: *mut u32) -> i32; +} + +/// `ID3D12Device::CreateCommandQueue`. +type CreateCommandQueue = unsafe extern "system" fn( + *mut c_void, + *const CommandQueueDesc, + *const Guid, + *mut *mut c_void, +) -> Hresult; + +/// `IUnknown::QueryInterface`, every COM object's method 0. +type QueryInterface = + unsafe extern "system" fn(*mut c_void, *const Guid, *mut *mut c_void) -> Hresult; + +/// What the module keeps: the vtables it set, and the devices held. +struct State { + vtables: Vec, + devices: Vec, +} + +/// A device class's vtable whose `CreateCommandQueue` slot the module set. +struct Vtable { + /// The vtable's address. + at: usize, + /// The slot's own method, kept for good. + original: CreateCommandQueue, + /// The holds on devices with this vtable. + holds: usize, +} + +/// A device held, and its video decode queues. +struct Held { + /// The device's identity: its `IUnknown` pointer. + identity: usize, + holds: usize, + /// Each queue made, by its description's priority, flags and node mask. + queues: Vec<((i32, u32, u32), Com)>, +} + +static STATE: Mutex = Mutex::new(State { + vtables: Vec::new(), + devices: Vec::new(), +}); + +/// A hold on a device's one video decode queue: while it lives, the device answers every ask for +/// a video decode queue with one queue. Let go of, it lets the device's queue and the vtable's +/// slot go as the module's doc says. +pub(super) struct Hold { + identity: usize, + vtable: usize, +} + +/// The address of `device`'s vtable: a COM object's first field. +fn vtable_of(device: *mut c_void) -> usize { + // SAFETY: `device` is a live COM object, whose first field is its vtable's address. + unsafe { *device.cast::() } +} + +/// The address of `vtable`'s `CreateCommandQueue` slot, as an atomic. +fn slot_of(vtable: usize) -> &'static AtomicUsize { + let slot = (vtable as *mut usize).wrapping_add(DEVICE_CREATE_COMMAND_QUEUE); + // SAFETY: a device class's vtable lives as long as its module, which the process does not + // unload while a device lives, and its slot holds a function's address, aligned as a usize. + unsafe { AtomicUsize::from_ptr(slot) } +} + +/// Sets `vtable`'s slot to `to`, under the module's lock: its old value. +fn set_slot(vtable: usize, to: usize) -> Result { + let slot = slot_of(vtable); + let at = slot.as_ptr().cast::(); + let mut old = 0; + // SAFETY: the slot is a usize of the vtable's, which the call makes writable. + let made = unsafe { VirtualProtect(at, size_of::(), PAGE_READWRITE, &mut old) }; + if made == 0 { + return Err(format!( + "VirtualProtect of the device's vtable failed: {}", + std::io::Error::last_os_error() + )); + } + let was = slot.swap(to, Ordering::SeqCst); + let mut unused = 0; + // SAFETY: as above, given back its protection. + unsafe { VirtualProtect(at, size_of::(), old, &mut unused) }; + Ok(was) +} + +/// The identity of the COM object `object`: its `IUnknown` pointer, released at once (the +/// caller holds the object). +fn identity_of(object: *mut c_void) -> Result { + let mut out = null_mut(); + // SAFETY: `object` is a live COM object, whose vtable's method 0 is `QueryInterface`. + let result = unsafe { + let vtable = *object.cast::<*const *const c_void>(); + let query = std::mem::transmute::<*const c_void, QueryInterface>(*vtable); + query(object, &IID_IUNKNOWN, &mut out) + }; + let unknown = Com::made("QueryInterface (IUnknown)", result, out)?; + Ok(unknown.raw() as usize) +} + +impl Hold { + /// A hold on `device`'s one video decode queue, setting its vtable's slot where no hold did. + pub(super) fn new(device: &Com) -> Result { + let identity = identity_of(device.raw())?; + let vtable = vtable_of(device.raw()); + let mut state = STATE.lock(); + match state.vtables.iter_mut().find(|kept| kept.at == vtable) { + Some(kept) if kept.holds > 0 => kept.holds += 1, + Some(kept) => { + let was = set_slot(vtable, create_command_queue as usize)?; + if was != create_command_queue as usize { + // SAFETY: the slot held `CreateCommandQueue`'s method, of that signature. + kept.original = + unsafe { std::mem::transmute::(was) }; + } + kept.holds = 1; + } + None => { + let was = set_slot(vtable, create_command_queue as usize)?; + // SAFETY: as above; this vtable was not set before, so the slot held its own. + let original = unsafe { std::mem::transmute::(was) }; + state.vtables.push(Vtable { + at: vtable, + original, + holds: 1, + }); + } + } + match state.devices.iter_mut().find(|held| held.identity == identity) { + Some(held) => held.holds += 1, + None => state.devices.push(Held { + identity, + holds: 1, + queues: Vec::new(), + }), + } + Ok(Hold { identity, vtable }) + } +} + +impl Drop for Hold { + fn drop(&mut self) { + let released; + { + let mut state = STATE.lock(); + let at = state + .devices + .iter() + .position(|held| held.identity == self.identity) + .expect("a hold's device is held"); + let held = &mut state.devices[at]; + held.holds -= 1; + released = (held.holds == 0).then(|| state.devices.swap_remove(at)); + let kept = state + .vtables + .iter_mut() + .find(|kept| kept.at == self.vtable) + .expect("a hold's vtable is kept"); + kept.holds -= 1; + let ours = slot_of(self.vtable).load(Ordering::SeqCst) == create_command_queue as usize; + if kept.holds == 0 && ours { + // Set back only where the slot still holds ours: something that set it after us + // calls ours, which passes through. + let _ = set_slot(self.vtable, kept.original as usize); + } + } + // The queues are released outside the lock: a release calls into the runtime. + drop(released); + } +} + +/// `ID3D12Device::CreateCommandQueue` on a device whose vtable the module set: its own method, +/// but for a video decode queue on a held device, which gets the device's one. +/// +/// # Safety +/// +/// The arguments are `CreateCommandQueue`'s: a live device, and the description, IID and out +/// pointer its caller gives it. +unsafe extern "system" fn create_command_queue( + device: *mut c_void, + desc: *const CommandQueueDesc, + iid: *const Guid, + out: *mut *mut c_void, +) -> Hresult { + let vtable = vtable_of(device); + let mut state = STATE.lock(); + let Some(original) = state + .vtables + .iter() + .find(|kept| kept.at == vtable) + .map(|kept| kept.original) + else { + // The slot is set only in vtables the module keeps. + return E_FAIL; + }; + // SAFETY: `desc` is the caller's description, read where it is not null. + let key = match unsafe { desc.as_ref() } { + Some(desc) if desc.type_ == VIDEO_DECODE => (desc.priority, desc.flags, desc.node_mask), + _ => { + drop(state); + // SAFETY: the slot's own method, given the caller's arguments. + return unsafe { original(device, desc, iid, out) }; + } + }; + let Ok(identity) = identity_of(device) else { + drop(state); + // SAFETY: as above. + return unsafe { original(device, desc, iid, out) }; + }; + let Some(held) = state.devices.iter_mut().find(|held| held.identity == identity) else { + drop(state); + // SAFETY: as above. + return unsafe { original(device, desc, iid, out) }; + }; + let at = match held.queues.iter().position(|(made, _)| *made == key) { + Some(at) => at, + None => { + let mut made = null_mut(); + // SAFETY: the slot's own method, given the caller's description, for the queue's + // ID3D12CommandQueue, which the module keeps. + let result = unsafe { original(device, desc, &IID_ID3D12_COMMAND_QUEUE, &mut made) }; + let Ok(queue) = Com::made("CreateCommandQueue (video decode)", result, made) else { + return result; + }; + held.queues.push((key, queue)); + held.queues.len() - 1 + } + }; + let queue = &held.queues[at].1; + // SAFETY: `QueryInterface` is every COM object's method 0, given the caller's IID and out + // pointer: it adds the reference the caller is given. + unsafe { + let query: QueryInterface = queue.method(0); + query(queue.raw(), iid, out) + } +} + +/// Makes a command queue of `type_` on `device` through its vtable, as Mesa does: its identity. +#[cfg(test)] +fn queue_identity(device: &Com, type_: u32) -> (Com, usize) { + let desc = CommandQueueDesc { + type_, + priority: 0, + flags: 0, + node_mask: 0, + }; + let mut out = null_mut(); + // SAFETY: the method is ID3D12Device's `CreateCommandQueue`, given a valid description and + // ID3D12CommandQueue's IID. + let result = unsafe { + let create: CreateCommandQueue = device.method(DEVICE_CREATE_COMMAND_QUEUE); + create(device.raw(), &desc, &IID_ID3D12_COMMAND_QUEUE, &mut out) + }; + let queue = Com::made("CreateCommandQueue", result, out).expect("a queue"); + let identity = identity_of(queue.raw()).expect("an identity"); + (queue, identity) +} + +/// A device of ours answers two asks for a video decode queue with one queue, and two asks for a +/// direct queue with two; let go of, it answers the next video decode asks with a queue each. +#[test] +#[ignore = "needs a Direct3D 12 device with video decode: run on the Windows host"] +fn a_held_devices_video_decode_queues_are_one_and_its_direct_queues_its_own() { + const DIRECT: u32 = 0; + let device = super::d3d12::Device::new(None).expect("a Direct3D 12 device"); + let (a, first) = queue_identity(&device.device, VIDEO_DECODE); + let (b, second) = queue_identity(&device.device, VIDEO_DECODE); + assert_eq!(first, second, "two video decode queues on a held device are one"); + let (c, direct) = queue_identity(&device.device, DIRECT); + let (d, other) = queue_identity(&device.device, DIRECT); + assert_ne!(direct, other, "two direct queues are their own"); + drop((a, b, c, d)); + // SAFETY: `AddRef` is every COM object's method 1: the reference added is `unheld`'s. + unsafe { + let add_ref: unsafe extern "system" fn(*mut c_void) -> u32 = device.device.method(1); + add_ref(device.device.raw()); + } + let unheld = Com::made("the device", 0, device.device.raw()).expect("the device"); + drop(device); + let (e, first) = queue_identity(&unheld, VIDEO_DECODE); + let (f, second) = queue_identity(&unheld, VIDEO_DECODE); + assert_ne!(first, second, "a device let go of answers a video decode queue each"); + drop((e, f)); +} diff --git a/crates/reims-vgpu-video/src/vaapi/va/teardown.rs b/crates/reims-vgpu-video/src/vaapi/va/teardown.rs index bdb029f78..37835f4a6 100644 --- a/crates/reims-vgpu-video/src/vaapi/va/teardown.rs +++ b/crates/reims-vgpu-video/src/vaapi/va/teardown.rs @@ -16,6 +16,9 @@ //! The full-pace test runs rounds of decoders that each decode the stream at once, each picture //! waited for and not read back, so that each decoder of a round but the last is let go while //! the others decode at full pace. +//! +//! Two decoders that decode at once compare their pictures with a lone decoder's: on Windows, +//! with one video decode queue on the device between them (`super::decode_queue`). use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; use std::sync::mpsc; @@ -488,6 +491,49 @@ fn short_decoders_let_go_beside_a_long_one_decode_alike_and_hold_no_more() { }); } +/// Two decoders decoding at once on one display, and so on Windows on one Direct3D 12 device, +/// decode the pictures a decoder alone decodes of the same access units. On Windows each decoder +/// of vaon12's asks the device for a video decode queue, and Intel's Direct3D 12 video driver +/// decodes wrong pictures on a device's later decode queue while an earlier one lives: this holds +/// there while the device answers them with one queue (`super::decode_queue`). +#[test] +#[ignore = "needs a VA-API driver that decodes H.264 at 4K, on its GPU: run on a VA-API host"] +fn two_decoders_at_once_on_one_display_decode_what_one_alone_does() { + let display = display(); + let stream = Stream::new(&display); + let samples = &stream.samples[..SHORT_SAMPLES.min(stream.samples.len())]; + let reference = pictures(&mut stream.decoder(&display), samples); + assert!( + reference.len() > 1, + "{} pictures of {} access units", + reference.len(), + samples.len() + ); + releases_made(&display); + let both = std::sync::Barrier::new(2); + let decoded: Vec> = std::thread::scope(|s| { + let decoders: Vec<_> = (0..2) + .map(|_| { + s.spawn(|| { + let mut decoder = stream.decoder(&display); + both.wait(); + pictures(&mut decoder, samples) + }) + }) + .collect(); + decoders.into_iter().map(|d| d.join().unwrap()).collect() + }); + for (n, got) in decoded.iter().enumerate() { + let differ: Vec = (0..reference.len().max(got.len())) + .filter(|&at| got.get(at) != reference.get(at)) + .collect(); + assert!( + differ.is_empty(), + "decoder {n}'s pictures not the lone decoder's at {differ:?}" + ); + } +} + /// The pictures decoded in /// [`a_display_let_go_after_its_decodes_leaves_no_reference_on_the_adapters_device`]. #[cfg(windows)] diff --git a/docs/video/bugs.md b/docs/video/bugs.md index f861c4e6f..674747704 100644 --- a/docs/video/bugs.md +++ b/docs/video/bugs.md @@ -138,6 +138,7 @@ Bugs in drivers, libraries and tools that our code or our checks work around. - **U30. iHD's decodes write their render target Y-tiled, whatever its import says.** Into an NV12 or P010 surface imported from a dma-buf (`VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2`, one object, one layer of two planes, `DRM_FORMAT_MOD_LINEAR`), an H.264 or HEVC decode answers success and writes each plane in Y tiles (tiles of 4 KiB, 128 bytes by 32 rows, laid in columns of 16 bytes): H.264's from each plane's offset, and HEVC's from each plane's offset where it is a whole tile in, else the luma plane from the dma-buf's first byte (**measured** on an Iris Xe of an i9-13900H, intel-media-driver 26.3.5, 2026-11-20, with the target check's streams: every luma and chroma byte of the check's first picture at its Y-tile place, the luma plane at 0, 256 and 4096 bytes of the dma-buf; the driver's own surfaces decode the same pictures to every sample). Its decode configs' surfaces take `VA_SURFACE_ATTRIB_MEM_TYPE_VA`, `DRM_PRIME_2` and `DRM_PRIME_3`, its video processing's but for `USER_PTR`, `KERNEL_DRM` and `DRM_PRIME` (0x48000001 against 0x78000005). So the target check fails every kind at its first picture on iHD, and no picture is decoded into memory of ours there. Ours: the arm makes the device's caches dma-bufs where the import check passed a format as well as where the target check passed a kind (`cache_writes`, `crates/reims-vgpu/src/graphics/vaapi.rs`), and iHD's video processing writes each picture, decoded into a surface of the driver's own, into its output's cache's surface (U26). Not reported upstream yet. - **U31. vaon12 keeps one Direct3D 12 object of every decode session past `vaTerminate`.** A VA decode context that decoded at least one picture leaves one object holding a reference on the adapter's Direct3D 12 device once the context, its surfaces and its config are destroyed and the display is terminated (`vaDestroyContext`, `vaDestroySurfaces`, `vaDestroyConfig`, `vaTerminate`): one for each session, whether it decoded 1, 2, 4, 8 or 16 pictures, each holding about 6.7 to 13 MiB of the adapter's local memory at 3840x2160. A context that decoded nothing, a pool of surfaces alone and a config alone leave none, and the surfaces' kind does not change it: the driver's own, or our shared textures imported by NT handle (**measured** on an Intel UHD Graphics 630, Mesa 26.2.7's vaon12, H.264 High at 3840x2160, 2026-11-20, with the VA crate's tests and probes of our own, the device's references counted by its `AddRef` and `Release` beside ours). The device answered decode tier 2 with no configuration flags for H.264 and HEVC Main and Main 10 at 1920x1080 and 3840x2160 (**measured**, same host and day), so vaon12 keeps its reference pictures as an array of textures and decodes into the target itself; which object stays is not plain from the driver's source (**read**, Mesa 26.2.7's `src/gallium/drivers/d3d12/d3d12_video_dec.cpp` and `src/gallium/frontends/va/`). The device is one an adapter and process, so it and those objects live until the process ends. Nothing in our order of calls reaches it: destroying a session's surfaces before its context instead left the device hung (the next `D3D12CreateDevice` answered `DXGI_ERROR_DEVICE_HUNG`), so ours keeps the context first. The VA crate's `a_display_let_go_after_its_decodes_leaves_no_reference_on_the_adapters_device` and `a_video_let_go_leaves_no_reference_on_the_adapters_device` hold what a driver without it does, and are ignored until one passes them. A report is written (the upstream folder's 126) and not filed yet. - **U32. iHD codes a frame from a linear encoder input otherwise than from its own surface.** Into an NV12 or P010 surface imported from a dma-buf (`VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2`, one object, one layer of two planes, `DRM_FORMAT_MOD_LINEAR`) as an encode's input, the same frame as uploaded into a surface of the driver's own codes to other bytes: H.264's P pictures at 640x360 and smaller, in Constrained Baseline, Main and High, at rows of the coded row's bytes rounded up to 64, 128 or 256 and the chroma plane right after the coded rows; every H.264 picture at 1280x720 and smaller at the driver's own pitch and offsets; every HEVC Main 10 picture, intra ones too; and at a pitch not a multiple of 64, even intra pictures. The driver's own inputs are Y-tiled (`I915_FORMAT_MOD_Y_TILED`), and an import declared Y-tiled in their layout, its bytes in Y tiles, coded as the upload did, byte for byte, at 320x192, 336x208, 640x360, 1280x720 and 1920x1080 in every profile, wherever two uploads coded the same bytes; HEVC Main at 640x360 and 1920x1080 differs from one upload to the next (**measured** with the VA crate's encoder and tests of our own, 6 frames of a moving ramp at a constant QP with no B pictures, an Iris Xe of an i9-13900H, intel-media-driver 26.3.5, libva 2.24.1, 2026-11-20). Ours: an encoder's imported input is laid out as the driver lays out its own where it lays them out in Y tiles (`VideoEncoder::input_layout`, `crates/reims-vgpu-video/src/vaapi/va/encoder.rs`, "Imported inputs"), and the rt platform's fill writes the frame there in Y tiles (`crates/reims-vgpu/src/graphics/vaapi/fill.rs`). A report is drafted (the upstream folder's 127) and not filed: it needs a program of its own first. +- **U33. Intel's Direct3D 12 video driver decodes wrong pictures on a device's later video decode queue.** On a Direct3D 12 device where a video decode queue (`D3D12_COMMAND_LIST_TYPE_VIDEO_DECODE`) lives, a decode on a queue made after it answers success and writes wrong pictures. vaon12 makes a video decode queue for each decoder, one a VA context (`d3d12_video_decoder_create_command_objects`, Mesa 26.2.7's `d3d12_video_dec.cpp`), all on the process's one device on the adapter, so of two sessions decoding at once on one display, one decoded wrong pictures, and so did the churn test's short decoders beside its long one (**measured** on an Intel UHD Graphics 630, `igd12dxva64.dll` 31.0.101.2145, Windows 10.0.26300, 2026-11-20). What makes a lone VA decoder's 8 pictures of a 4K H.264 stream wrong, made on the device before it (potluck job m3-max-62074, twice): an idle video decode queue, 8 of 8 wrong; that queue, an `ID3D12VideoDecoder` and an `ID3D12VideoDecoderHeap`, 8 of 8; the decoder, the heap, or both, without the queue, none; nothing, none. FFmpeg 9.0.2's D3D12 decoders (`-hwaccel d3d12va`), each on a queue of its own, show it without Mesa: of two or three decoding at once in one process, one decoded the software decode's frames and the others none, at 3840x2160 and 1920x1080, in H.264 and HEVC; its D3D11 decoders two at once in one process, and two processes at once, decoded every frame right. Ours: while a display's device lives, the device answers every ask for a video decode queue with one queue (`crates/reims-vgpu-video/src/vaapi/va/decode_queue.rs`, [vaapi.md](vaapi.md), "On Windows a device makes one video decode queue"), and `two_decoders_at_once_on_one_display_decode_what_one_alone_does` holds it. Not reported upstream yet: a report, with a program of our own on Direct3D 12 alone, is written (the upstream folder's 128). ## Untested, or tested by unit tests only diff --git a/docs/video/vaapi.md b/docs/video/vaapi.md index c14b4daa2..dd3f39f9c 100644 --- a/docs/video/vaapi.md +++ b/docs/video/vaapi.md @@ -644,6 +644,25 @@ The thread starts with the first order and ends after `vaTerminate`. Where it cannot start, the log says so, and orders are made on their callers' threads with no bound. +**On Windows a device makes one video decode queue** +(`src/vaapi/va/decode_queue.rs`): vaon12 makes a Direct3D 12 video +decode queue for each decoder, one a VA context, on the process's one +device on the adapter, and Intel's Direct3D 12 video driver decodes wrong +pictures on a device's later video decode queue while an earlier one +lives ([bugs.md](bugs.md), U33). So while a display's device lives +(`d3d12::Device`), the device's `CreateCommandQueue` answers every ask +for a video decode queue with one queue, a reference added for each +asker, and makes every other queue as before; the vendor does not decide. +**Measured** on the UHD Graphics 630 (2026-11-20, potluck job +m3-max-62121): with it two decoders at once decoded a lone decoder's +pictures, 3 runs of 3, and the churn test's ten short decoders the long +one's, 3 runs of 3, where with a queue each one of the two, and every +short decoder, decoded wrong pictures. 4K H.264 sessions decoding at +once, each picture waited for and not read back, kept their rate: with +one queue 25.4 to 27.4 pictures a second alone, 53.2 to 56.1 in all two +at once and 113.6 to 116.0 four at once, against 22.9 to 26.9, 49.7 to +52.2 and 101.8 to 111.9 with a queue each, 2 runs of each, alternated. + **On Windows a teardown waits for the display's other contexts** (`Display::release_teardown`): the destroy of a context, of a config or of a pool's surfaces, asked for while a context lives on the display (for