From 5f59ead42321abee16b0959ba286f5988cff6669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 13:40:07 +0300 Subject: [PATCH] U17: ec-va drop cacheline.rs, abi-probe.c, open_path, Config::profile/entrypoint, Profile::is_family_codec and Error::Drm (no caller in the workspace, edith or yumush) --- crates/ec-va/abi-probe.c | 90 ----------------------------------- crates/ec-va/src/cacheline.rs | 78 ------------------------------ crates/ec-va/src/caps.rs | 19 -------- crates/ec-va/src/config.rs | 20 +------- crates/ec-va/src/display.rs | 9 ---- crates/ec-va/src/error.rs | 8 ---- crates/ec-va/src/lib.rs | 3 +- 7 files changed, 3 insertions(+), 224 deletions(-) delete mode 100644 crates/ec-va/abi-probe.c delete mode 100644 crates/ec-va/src/cacheline.rs diff --git a/crates/ec-va/abi-probe.c b/crates/ec-va/abi-probe.c deleted file mode 100644 index 951fea88..00000000 --- a/crates/ec-va/abi-probe.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * ABI probe for the hand-written libva FFI in src/sys.rs. - * - * src/sys.rs transcribes libva struct layouts by hand (no bindgen, family rule). - * This probe is the evidence for that transcription: it prints the sizes, - * alignments and field offsets that the *system* headers produce, so the - * `const _: () = assert!(...)` block in sys.rs can be checked against a real - * compiler instead of against a reading of the header. - * - * Run: - * cc -o /tmp/ec-va-abi-probe crates/ec-va/abi-probe.c $(pkg-config --cflags --libs libva) \ - * && /tmp/ec-va-abi-probe - * - * Recorded output (libva 1.23.0, x86_64-unknown-linux-gnu, gcc 15) is pasted - * into the assertion block in sys.rs. Any mismatch after a libva upgrade means - * the transcription drifted — the exact failure mode that broke cros-libva at - * libva >= 1.23. - */ -#include -#include -#include -#include - -#define SA(T) printf("%-32s size=%-5zu align=%zu\n", #T, sizeof(T), _Alignof(T)) -#define OF(T, F) printf(" %-30s offset=%zu\n", #T "." #F, offsetof(T, F)) - -int main(void) -{ - printf("libva headers: %s\n", VA_VERSION_S); - - SA(VAStatus); - SA(VAGenericID); - SA(VAProfile); - SA(VAEntrypoint); - SA(VAConfigAttribType); - SA(VAConfigAttrib); - OF(VAConfigAttrib, type); - OF(VAConfigAttrib, value); - - SA(VAGenericValue); - OF(VAGenericValue, type); - OF(VAGenericValue, value); - - SA(VASurfaceAttrib); - OF(VASurfaceAttrib, type); - OF(VASurfaceAttrib, flags); - OF(VASurfaceAttrib, value); - - SA(VAImageFormat); - OF(VAImageFormat, fourcc); - OF(VAImageFormat, byte_order); - OF(VAImageFormat, bits_per_pixel); - OF(VAImageFormat, depth); - OF(VAImageFormat, red_mask); - OF(VAImageFormat, alpha_mask); - OF(VAImageFormat, va_reserved); - - SA(VAImage); - OF(VAImage, image_id); - OF(VAImage, format); - OF(VAImage, buf); - OF(VAImage, width); - OF(VAImage, height); - OF(VAImage, data_size); - OF(VAImage, num_planes); - OF(VAImage, pitches); - OF(VAImage, offsets); - OF(VAImage, num_palette_entries); - OF(VAImage, entry_bytes); - OF(VAImage, component_order); - OF(VAImage, va_reserved); - - SA(VADRMPRIMESurfaceDescriptor); - OF(VADRMPRIMESurfaceDescriptor, fourcc); - OF(VADRMPRIMESurfaceDescriptor, width); - OF(VADRMPRIMESurfaceDescriptor, height); - OF(VADRMPRIMESurfaceDescriptor, num_objects); - OF(VADRMPRIMESurfaceDescriptor, objects); - OF(VADRMPRIMESurfaceDescriptor, num_layers); - OF(VADRMPRIMESurfaceDescriptor, layers); - printf(" object elem size=%zu align=%zu\n", - sizeof(((VADRMPRIMESurfaceDescriptor *)0)->objects[0]), - _Alignof(((VADRMPRIMESurfaceDescriptor *)0)->objects[0])); - printf(" layer elem size=%zu align=%zu\n", - sizeof(((VADRMPRIMESurfaceDescriptor *)0)->layers[0]), - _Alignof(((VADRMPRIMESurfaceDescriptor *)0)->layers[0])); - - SA(VARectangle); - return 0; -} diff --git a/crates/ec-va/src/cacheline.rs b/crates/ec-va/src/cacheline.rs deleted file mode 100644 index adfb03ca..00000000 --- a/crates/ec-va/src/cacheline.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! Which cache lines a CPU write-back of a mapped DMA-BUF has to visit. -//! -//! `CLFLUSH` takes an address and writes back the whole cache line holding it, -//! so a buffer needs one flush per line, not one per byte. The incumbent -//! stack flushed every byte (64 instructions per line, 6.2 ms per 1080p -//! picture on radeonsi). The base of a mapping is not guaranteed to be cache -//! aligned, so the last byte's line is flushed too: a range that starts -//! mid-line can straddle one more line than its length suggests. - -/// Bytes per cache line on every x86-64 part this crate targets. -pub const CACHE_LINE: usize = 64; - -/// Offsets from a mapping's base at which to issue a flush for a buffer of -/// `len` bytes: one per [`CACHE_LINE`], plus the last byte when the stride -/// does not land on it. Empty for `len == 0`, which has no line to flush. -pub fn flush_offsets(len: usize) -> Vec { - if len == 0 { - return Vec::new(); - } - let last = len - 1; - let mut offsets: Vec = (0..len).step_by(CACHE_LINE).collect(); - if offsets.last() != Some(&last) { - offsets.push(last); - } - offsets -} - -#[cfg(test)] -mod tests { - use super::*; - - /// The absolute cache-line indices a flush at `offsets` writes back, for a - /// mapping whose base sits `base_mod` bytes into a line. - fn lines_flushed(base_mod: usize, offsets: &[usize]) -> Vec { - let base = 1000 * CACHE_LINE + base_mod; - let mut lines: Vec = offsets.iter().map(|o| (base + o) / CACHE_LINE).collect(); - lines.sort_unstable(); - lines.dedup(); - lines - } - - #[test] - fn empty_buffer_has_nothing_to_flush() { - assert!(flush_offsets(0).is_empty()); - } - - #[test] - fn one_flush_per_line_not_per_byte() { - assert_eq!(flush_offsets(1), vec![0]); - // 64 bytes from an unaligned base can still straddle two lines: the last byte too. - assert_eq!(flush_offsets(64), vec![0, 63]); - assert_eq!(flush_offsets(65), vec![0, 64]); - assert_eq!(flush_offsets(128), vec![0, 64, 127]); - // A 1080p NV12 picture (~3.1 MB) is ~48K flushes, not ~3.1M. - assert!(flush_offsets(1920 * 1620).len() <= 1920 * 1620 / CACHE_LINE + 2); - } - - // Regression for the straddle: with an unaligned base, the bytes of a - // range can sit in one more line than a stride from the base reaches, so - // every byte's line must be among the flushed lines for every alignment. - #[test] - fn every_byte_is_covered_for_every_base_alignment() { - for base_mod in 0..CACHE_LINE { - for len in 0..=300 { - let offsets = flush_offsets(len); - let flushed = lines_flushed(base_mod, &offsets); - let base = 1000 * CACHE_LINE + base_mod; - for i in 0..len { - let line = (base + i) / CACHE_LINE; - assert!( - flushed.contains(&line), - "base_mod {base_mod} len {len}: byte {i} (line {line}) not flushed" - ); - } - } - } - } -} diff --git a/crates/ec-va/src/caps.rs b/crates/ec-va/src/caps.rs index c37583e8..d879e39e 100644 --- a/crates/ec-va/src/caps.rs +++ b/crates/ec-va/src/caps.rs @@ -127,25 +127,6 @@ va_enum! { } } -impl Profile { - /// True for the profiles the family decodes or encodes in hardware. - pub fn is_family_codec(self) -> bool { - matches!( - self, - Profile::H264ConstrainedBaseline - | Profile::H264Main - | Profile::H264High - | Profile::H264High10 - | Profile::HEVCMain - | Profile::HEVCMain10 - | Profile::VP9Profile0 - | Profile::VP9Profile2 - | Profile::AV1Profile0 - | Profile::AV1Profile2 - ) - } -} - /// What one (profile, entrypoint) pair supports. /// One supported (profile, entrypoint) pair and what the driver says about it. #[derive(Debug, Clone)] diff --git a/crates/ec-va/src/config.rs b/crates/ec-va/src/config.rs index e8591a6c..77cf20b2 100644 --- a/crates/ec-va/src/config.rs +++ b/crates/ec-va/src/config.rs @@ -64,11 +64,9 @@ impl SurfaceCaps { } } -/// A live `VAConfigID`, remembering the profile and entrypoint it was made for. +/// A live `VAConfigID`. pub struct Config { inner: cros_libva::Config, - profile: Profile, - entrypoint: Entrypoint, } impl Config { @@ -90,21 +88,7 @@ impl Config { "vaCreateConfig", display.create_config(attrs, profile.as_raw(), entrypoint.as_raw()), )?; - Ok(Config { - inner, - profile, - entrypoint, - }) - } - - /// The profile this config decodes or encodes. - pub fn profile(&self) -> Profile { - self.profile - } - - /// The entrypoint this config was created for. - pub fn entrypoint(&self) -> Entrypoint { - self.entrypoint + Ok(Config { inner }) } /// The cros-libva handle, for the calls that take one. diff --git a/crates/ec-va/src/display.rs b/crates/ec-va/src/display.rs index 972d439a..3978fb60 100644 --- a/crates/ec-va/src/display.rs +++ b/crates/ec-va/src/display.rs @@ -1,6 +1,5 @@ //! Opening a VA display on a DRM render node. -use std::path::Path; use std::rc::Rc; use crate::error::{Error, Result}; @@ -14,14 +13,6 @@ pub fn open() -> Result> { Display::open().ok_or(Error::NoDevice) } -/// Open a specific DRM render node. -pub fn open_path(path: &Path) -> Result> { - Display::open_drm_display(path).map_err(|e| Error::Drm { - path: path.display().to_string(), - message: format!("{e:?}"), - }) -} - /// The driver's vendor string (`vaQueryVendorString`). pub fn vendor(display: &Display) -> Result { display diff --git a/crates/ec-va/src/error.rs b/crates/ec-va/src/error.rs index 89d46b6d..d51379ed 100644 --- a/crates/ec-va/src/error.rs +++ b/crates/ec-va/src/error.rs @@ -21,13 +21,6 @@ pub enum Error { /// libva's description of `status`. message: String, }, - /// A DRM render node could not be opened as a VA display. - Drm { - /// The node that was tried. - path: String, - /// Why it failed. - message: String, - }, /// No usable `/dev/dri/renderD*` VA display exists. NoDevice, /// libva returned a value this crate cannot interpret. @@ -66,7 +59,6 @@ impl fmt::Display for Error { status, message, } => write!(f, "{op} failed: {message} (VAStatus 0x{status:08x})"), - Error::Drm { path, message } => write!(f, "opening DRM node {path}: {message}"), Error::NoDevice => write!(f, "no usable /dev/dri/renderD* VA display"), Error::Protocol(what) => write!(f, "libva returned an uninterpretable value: {what}"), } diff --git a/crates/ec-va/src/lib.rs b/crates/ec-va/src/lib.rs index d9a3b6ef..889857e7 100644 --- a/crates/ec-va/src/lib.rs +++ b/crates/ec-va/src/lib.rs @@ -34,7 +34,6 @@ #![forbid(unsafe_code)] #![deny(missing_docs)] -pub mod cacheline; pub mod caps; pub mod config; pub mod display; @@ -47,7 +46,7 @@ pub use cros_libva as va; pub use caps::{CapEntry, CapReport, Entrypoint, Profile, fourcc_str}; pub use config::{Config, ConfigAttrib, SurfaceCaps, caps_of}; -pub use display::{Display, open, open_path}; +pub use display::{Display, open}; pub use error::{Error, Result}; pub use picture::{Buffer, Context, Picture, create_context}; pub use surface::{