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)
Browse files at this commit5f59ead42321abee16b0959ba286f5988cff6669Parent: 894968f7 changed files +3 -224
- crates/ec-va/abi-probe.c +0 -90
- crates/ec-va/src/cacheline.rs +0 -78
- crates/ec-va/src/caps.rs +0 -19
- crates/ec-va/src/config.rs +2 -18
- crates/ec-va/src/display.rs +0 -9
- crates/ec-va/src/error.rs +0 -8
- crates/ec-va/src/lib.rs +1 -2
crates/ec-va/abi-probe.cdeleted+0 -90
| @@ -1,90 +0,0 @@ | |||
| 1 | -/* | ||
| 2 | - * ABI probe for the hand-written libva FFI in src/sys.rs. | ||
| 3 | - * | ||
| 4 | - * src/sys.rs transcribes libva struct layouts by hand (no bindgen, family rule). | ||
| 5 | - * This probe is the evidence for that transcription: it prints the sizes, | ||
| 6 | - * alignments and field offsets that the *system* headers produce, so the | ||
| 7 | - * `const _: () = assert!(...)` block in sys.rs can be checked against a real | ||
| 8 | - * compiler instead of against a reading of the header. | ||
| 9 | - * | ||
| 10 | - * Run: | ||
| 11 | - * cc -o /tmp/ec-va-abi-probe crates/ec-va/abi-probe.c $(pkg-config --cflags --libs libva) \ | ||
| 12 | - * && /tmp/ec-va-abi-probe | ||
| 13 | - * | ||
| 14 | - * Recorded output (libva 1.23.0, x86_64-unknown-linux-gnu, gcc 15) is pasted | ||
| 15 | - * into the assertion block in sys.rs. Any mismatch after a libva upgrade means | ||
| 16 | - * the transcription drifted — the exact failure mode that broke cros-libva at | ||
| 17 | - * libva >= 1.23. | ||
| 18 | - */ | ||
| 19 | -#include <stdio.h> | ||
| 20 | -#include <stddef.h> | ||
| 21 | -#include <va/va.h> | ||
| 22 | -#include <va/va_drmcommon.h> | ||
| 23 | - | ||
| 24 | -#define SA(T) printf("%-32s size=%-5zu align=%zu\n", #T, sizeof(T), _Alignof(T)) | ||
| 25 | -#define OF(T, F) printf(" %-30s offset=%zu\n", #T "." #F, offsetof(T, F)) | ||
| 26 | - | ||
| 27 | -int main(void) | ||
| 28 | -{ | ||
| 29 | - printf("libva headers: %s\n", VA_VERSION_S); | ||
| 30 | - | ||
| 31 | - SA(VAStatus); | ||
| 32 | - SA(VAGenericID); | ||
| 33 | - SA(VAProfile); | ||
| 34 | - SA(VAEntrypoint); | ||
| 35 | - SA(VAConfigAttribType); | ||
| 36 | - SA(VAConfigAttrib); | ||
| 37 | - OF(VAConfigAttrib, type); | ||
| 38 | - OF(VAConfigAttrib, value); | ||
| 39 | - | ||
| 40 | - SA(VAGenericValue); | ||
| 41 | - OF(VAGenericValue, type); | ||
| 42 | - OF(VAGenericValue, value); | ||
| 43 | - | ||
| 44 | - SA(VASurfaceAttrib); | ||
| 45 | - OF(VASurfaceAttrib, type); | ||
| 46 | - OF(VASurfaceAttrib, flags); | ||
| 47 | - OF(VASurfaceAttrib, value); | ||
| 48 | - | ||
| 49 | - SA(VAImageFormat); | ||
| 50 | - OF(VAImageFormat, fourcc); | ||
| 51 | - OF(VAImageFormat, byte_order); | ||
| 52 | - OF(VAImageFormat, bits_per_pixel); | ||
| 53 | - OF(VAImageFormat, depth); | ||
| 54 | - OF(VAImageFormat, red_mask); | ||
| 55 | - OF(VAImageFormat, alpha_mask); | ||
| 56 | - OF(VAImageFormat, va_reserved); | ||
| 57 | - | ||
| 58 | - SA(VAImage); | ||
| 59 | - OF(VAImage, image_id); | ||
| 60 | - OF(VAImage, format); | ||
| 61 | - OF(VAImage, buf); | ||
| 62 | - OF(VAImage, width); | ||
| 63 | - OF(VAImage, height); | ||
| 64 | - OF(VAImage, data_size); | ||
| 65 | - OF(VAImage, num_planes); | ||
| 66 | - OF(VAImage, pitches); | ||
| 67 | - OF(VAImage, offsets); | ||
| 68 | - OF(VAImage, num_palette_entries); | ||
| 69 | - OF(VAImage, entry_bytes); | ||
| 70 | - OF(VAImage, component_order); | ||
| 71 | - OF(VAImage, va_reserved); | ||
| 72 | - | ||
| 73 | - SA(VADRMPRIMESurfaceDescriptor); | ||
| 74 | - OF(VADRMPRIMESurfaceDescriptor, fourcc); | ||
| 75 | - OF(VADRMPRIMESurfaceDescriptor, width); | ||
| 76 | - OF(VADRMPRIMESurfaceDescriptor, height); | ||
| 77 | - OF(VADRMPRIMESurfaceDescriptor, num_objects); | ||
| 78 | - OF(VADRMPRIMESurfaceDescriptor, objects); | ||
| 79 | - OF(VADRMPRIMESurfaceDescriptor, num_layers); | ||
| 80 | - OF(VADRMPRIMESurfaceDescriptor, layers); | ||
| 81 | - printf(" object elem size=%zu align=%zu\n", | ||
| 82 | - sizeof(((VADRMPRIMESurfaceDescriptor *)0)->objects[0]), | ||
| 83 | - _Alignof(((VADRMPRIMESurfaceDescriptor *)0)->objects[0])); | ||
| 84 | - printf(" layer elem size=%zu align=%zu\n", | ||
| 85 | - sizeof(((VADRMPRIMESurfaceDescriptor *)0)->layers[0]), | ||
| 86 | - _Alignof(((VADRMPRIMESurfaceDescriptor *)0)->layers[0])); | ||
| 87 | - | ||
| 88 | - SA(VARectangle); | ||
| 89 | - return 0; | ||
| 90 | -} | ||
crates/ec-va/src/cacheline.rsdeleted+0 -78
| @@ -1,78 +0,0 @@ | |||
| 1 | -//! Which cache lines a CPU write-back of a mapped DMA-BUF has to visit. | ||
| 2 | -//! | ||
| 3 | -//! `CLFLUSH` takes an address and writes back the whole cache line holding it, | ||
| 4 | -//! so a buffer needs one flush per line, not one per byte. The incumbent | ||
| 5 | -//! stack flushed every byte (64 instructions per line, 6.2 ms per 1080p | ||
| 6 | -//! picture on radeonsi). The base of a mapping is not guaranteed to be cache | ||
| 7 | -//! aligned, so the last byte's line is flushed too: a range that starts | ||
| 8 | -//! mid-line can straddle one more line than its length suggests. | ||
| 9 | - | ||
| 10 | -/// Bytes per cache line on every x86-64 part this crate targets. | ||
| 11 | -pub const CACHE_LINE: usize = 64; | ||
| 12 | - | ||
| 13 | -/// Offsets from a mapping's base at which to issue a flush for a buffer of | ||
| 14 | -/// `len` bytes: one per [`CACHE_LINE`], plus the last byte when the stride | ||
| 15 | -/// does not land on it. Empty for `len == 0`, which has no line to flush. | ||
| 16 | -pub fn flush_offsets(len: usize) -> Vec<usize> { | ||
| 17 | - if len == 0 { | ||
| 18 | - return Vec::new(); | ||
| 19 | - } | ||
| 20 | - let last = len - 1; | ||
| 21 | - let mut offsets: Vec<usize> = (0..len).step_by(CACHE_LINE).collect(); | ||
| 22 | - if offsets.last() != Some(&last) { | ||
| 23 | - offsets.push(last); | ||
| 24 | - } | ||
| 25 | - offsets | ||
| 26 | -} | ||
| 27 | - | ||
| 28 | -#[cfg(test)] | ||
| 29 | -mod tests { | ||
| 30 | - use super::*; | ||
| 31 | - | ||
| 32 | - /// The absolute cache-line indices a flush at `offsets` writes back, for a | ||
| 33 | - /// mapping whose base sits `base_mod` bytes into a line. | ||
| 34 | - fn lines_flushed(base_mod: usize, offsets: &[usize]) -> Vec<usize> { | ||
| 35 | - let base = 1000 * CACHE_LINE + base_mod; | ||
| 36 | - let mut lines: Vec<usize> = offsets.iter().map(|o| (base + o) / CACHE_LINE).collect(); | ||
| 37 | - lines.sort_unstable(); | ||
| 38 | - lines.dedup(); | ||
| 39 | - lines | ||
| 40 | - } | ||
| 41 | - | ||
| 42 | - #[test] | ||
| 43 | - fn empty_buffer_has_nothing_to_flush() { | ||
| 44 | - assert!(flush_offsets(0).is_empty()); | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - #[test] | ||
| 48 | - fn one_flush_per_line_not_per_byte() { | ||
| 49 | - assert_eq!(flush_offsets(1), vec![0]); | ||
| 50 | - // 64 bytes from an unaligned base can still straddle two lines: the last byte too. | ||
| 51 | - assert_eq!(flush_offsets(64), vec![0, 63]); | ||
| 52 | - assert_eq!(flush_offsets(65), vec![0, 64]); | ||
| 53 | - assert_eq!(flush_offsets(128), vec![0, 64, 127]); | ||
| 54 | - // A 1080p NV12 picture (~3.1 MB) is ~48K flushes, not ~3.1M. | ||
| 55 | - assert!(flush_offsets(1920 * 1620).len() <= 1920 * 1620 / CACHE_LINE + 2); | ||
| 56 | - } | ||
| 57 | - | ||
| 58 | - // Regression for the straddle: with an unaligned base, the bytes of a | ||
| 59 | - // range can sit in one more line than a stride from the base reaches, so | ||
| 60 | - // every byte's line must be among the flushed lines for every alignment. | ||
| 61 | - #[test] | ||
| 62 | - fn every_byte_is_covered_for_every_base_alignment() { | ||
| 63 | - for base_mod in 0..CACHE_LINE { | ||
| 64 | - for len in 0..=300 { | ||
| 65 | - let offsets = flush_offsets(len); | ||
| 66 | - let flushed = lines_flushed(base_mod, &offsets); | ||
| 67 | - let base = 1000 * CACHE_LINE + base_mod; | ||
| 68 | - for i in 0..len { | ||
| 69 | - let line = (base + i) / CACHE_LINE; | ||
| 70 | - assert!( | ||
| 71 | - flushed.contains(&line), | ||
| 72 | - "base_mod {base_mod} len {len}: byte {i} (line {line}) not flushed" | ||
| 73 | - ); | ||
| 74 | - } | ||
| 75 | - } | ||
| 76 | - } | ||
| 77 | - } | ||
| 78 | -} | ||
crates/ec-va/src/caps.rsmodified+0 -19
| @@ -127,25 +127,6 @@ va_enum! { | |||
| 127 | } | 127 | } |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | -impl Profile { | ||
| 131 | - /// True for the profiles the family decodes or encodes in hardware. | ||
| 132 | - pub fn is_family_codec(self) -> bool { | ||
| 133 | - matches!( | ||
| 134 | - self, | ||
| 135 | - Profile::H264ConstrainedBaseline | ||
| 136 | - | Profile::H264Main | ||
| 137 | - | Profile::H264High | ||
| 138 | - | Profile::H264High10 | ||
| 139 | - | Profile::HEVCMain | ||
| 140 | - | Profile::HEVCMain10 | ||
| 141 | - | Profile::VP9Profile0 | ||
| 142 | - | Profile::VP9Profile2 | ||
| 143 | - | Profile::AV1Profile0 | ||
| 144 | - | Profile::AV1Profile2 | ||
| 145 | - ) | ||
| 146 | - } | ||
| 147 | -} | ||
| 148 | - | ||
| 149 | /// What one (profile, entrypoint) pair supports. | 130 | /// What one (profile, entrypoint) pair supports. |
| 150 | /// One supported (profile, entrypoint) pair and what the driver says about it. | 131 | /// One supported (profile, entrypoint) pair and what the driver says about it. |
| 151 | #[derive(Debug, Clone)] | 132 | #[derive(Debug, Clone)] |
crates/ec-va/src/config.rsmodified+2 -18
| @@ -64,11 +64,9 @@ impl SurfaceCaps { | |||
| 64 | } | 64 | } |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | -/// A live `VAConfigID`, remembering the profile and entrypoint it was made for. | 67 | +/// A live `VAConfigID`. |
| 68 | pub struct Config { | 68 | pub struct Config { |
| 69 | inner: cros_libva::Config, | 69 | inner: cros_libva::Config, |
| 70 | - profile: Profile, | ||
| 71 | - entrypoint: Entrypoint, | ||
| 72 | } | 70 | } |
| 73 | 71 | ||
| 74 | impl Config { | 72 | impl Config { |
| @@ -90,21 +88,7 @@ impl Config { | |||
| 90 | "vaCreateConfig", | 88 | "vaCreateConfig", |
| 91 | display.create_config(attrs, profile.as_raw(), entrypoint.as_raw()), | 89 | display.create_config(attrs, profile.as_raw(), entrypoint.as_raw()), |
| 92 | )?; | 90 | )?; |
| 93 | - Ok(Config { | 91 | + Ok(Config { inner }) |
| 94 | - inner, | ||
| 95 | - profile, | ||
| 96 | - entrypoint, | ||
| 97 | - }) | ||
| 98 | - } | ||
| 99 | - | ||
| 100 | - /// The profile this config decodes or encodes. | ||
| 101 | - pub fn profile(&self) -> Profile { | ||
| 102 | - self.profile | ||
| 103 | - } | ||
| 104 | - | ||
| 105 | - /// The entrypoint this config was created for. | ||
| 106 | - pub fn entrypoint(&self) -> Entrypoint { | ||
| 107 | - self.entrypoint | ||
| 108 | } | 92 | } |
| 109 | 93 | ||
| 110 | /// The cros-libva handle, for the calls that take one. | 94 | /// The cros-libva handle, for the calls that take one. |
crates/ec-va/src/display.rsmodified+0 -9
| @@ -1,6 +1,5 @@ | |||
| 1 | //! Opening a VA display on a DRM render node. | 1 | //! Opening a VA display on a DRM render node. |
| 2 | 2 | ||
| 3 | -use std::path::Path; | ||
| 4 | use std::rc::Rc; | 3 | use std::rc::Rc; |
| 5 | 4 | ||
| 6 | use crate::error::{Error, Result}; | 5 | use crate::error::{Error, Result}; |
| @@ -14,14 +13,6 @@ pub fn open() -> Result<Rc<Display>> { | |||
| 14 | Display::open().ok_or(Error::NoDevice) | 13 | Display::open().ok_or(Error::NoDevice) |
| 15 | } | 14 | } |
| 16 | 15 | ||
| 17 | -/// Open a specific DRM render node. | ||
| 18 | -pub fn open_path(path: &Path) -> Result<Rc<Display>> { | ||
| 19 | - Display::open_drm_display(path).map_err(|e| Error::Drm { | ||
| 20 | - path: path.display().to_string(), | ||
| 21 | - message: format!("{e:?}"), | ||
| 22 | - }) | ||
| 23 | -} | ||
| 24 | - | ||
| 25 | /// The driver's vendor string (`vaQueryVendorString`). | 16 | /// The driver's vendor string (`vaQueryVendorString`). |
| 26 | pub fn vendor(display: &Display) -> Result<String> { | 17 | pub fn vendor(display: &Display) -> Result<String> { |
| 27 | display | 18 | display |
crates/ec-va/src/error.rsmodified+0 -8
| @@ -21,13 +21,6 @@ pub enum Error { | |||
| 21 | /// libva's description of `status`. | 21 | /// libva's description of `status`. |
| 22 | message: String, | 22 | message: String, |
| 23 | }, | 23 | }, |
| 24 | - /// A DRM render node could not be opened as a VA display. | ||
| 25 | - Drm { | ||
| 26 | - /// The node that was tried. | ||
| 27 | - path: String, | ||
| 28 | - /// Why it failed. | ||
| 29 | - message: String, | ||
| 30 | - }, | ||
| 31 | /// No usable `/dev/dri/renderD*` VA display exists. | 24 | /// No usable `/dev/dri/renderD*` VA display exists. |
| 32 | NoDevice, | 25 | NoDevice, |
| 33 | /// libva returned a value this crate cannot interpret. | 26 | /// libva returned a value this crate cannot interpret. |
| @@ -66,7 +59,6 @@ impl fmt::Display for Error { | |||
| 66 | status, | 59 | status, |
| 67 | message, | 60 | message, |
| 68 | } => write!(f, "{op} failed: {message} (VAStatus 0x{status:08x})"), | 61 | } => write!(f, "{op} failed: {message} (VAStatus 0x{status:08x})"), |
| 69 | - Error::Drm { path, message } => write!(f, "opening DRM node {path}: {message}"), | ||
| 70 | Error::NoDevice => write!(f, "no usable /dev/dri/renderD* VA display"), | 62 | Error::NoDevice => write!(f, "no usable /dev/dri/renderD* VA display"), |
| 71 | Error::Protocol(what) => write!(f, "libva returned an uninterpretable value: {what}"), | 63 | Error::Protocol(what) => write!(f, "libva returned an uninterpretable value: {what}"), |
| 72 | } | 64 | } |
crates/ec-va/src/lib.rsmodified+1 -2
| @@ -34,7 +34,6 @@ | |||
| 34 | #![forbid(unsafe_code)] | 34 | #![forbid(unsafe_code)] |
| 35 | #![deny(missing_docs)] | 35 | #![deny(missing_docs)] |
| 36 | 36 | ||
| 37 | -pub mod cacheline; | ||
| 38 | pub mod caps; | 37 | pub mod caps; |
| 39 | pub mod config; | 38 | pub mod config; |
| 40 | pub mod display; | 39 | pub mod display; |
| @@ -47,7 +46,7 @@ pub use cros_libva as va; | |||
| 47 | 46 | ||
| 48 | pub use caps::{CapEntry, CapReport, Entrypoint, Profile, fourcc_str}; | 47 | pub use caps::{CapEntry, CapReport, Entrypoint, Profile, fourcc_str}; |
| 49 | pub use config::{Config, ConfigAttrib, SurfaceCaps, caps_of}; | 48 | pub use config::{Config, ConfigAttrib, SurfaceCaps, caps_of}; |
| 50 | -pub use display::{Display, open, open_path}; | 49 | +pub use display::{Display, open}; |
| 51 | pub use error::{Error, Result}; | 50 | pub use error::{Error, Result}; |
| 52 | pub use picture::{Buffer, Context, Picture, create_context}; | 51 | pub use picture::{Buffer, Context, Picture, create_context}; |
| 53 | pub use surface::{ | 52 | pub use surface::{ |