edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB84fa44cTahinli2 months ago3331 commits
| 1 | //! `#[repr(C)]` transcriptions of the libva codec parameter structs. |
| 2 | //! |
| 3 | //! `ec-va` deliberately stops at the generic VA surface (display, config, |
| 4 | //! context, buffer, picture); the per-codec buffers live here because they are |
| 5 | //! what a *decoder* is, field for field. Every struct is transcribed by hand |
| 6 | //! from the system headers, in header order, and every one of them is checked |
| 7 | //! against `crates/ec-hw/abi-probe.c` output by the `const` assertion block at |
| 8 | //! the end of its module. A transcription slip is therefore a compile error, |
| 9 | //! not a driver reading garbage. |
| 10 | //! |
| 11 | //! Reference output of the probe (libva 1.23.0, x86_64 System V) is pasted |
| 12 | //! above each assertion block. Rerun it after a libva upgrade: |
| 13 | //! |
| 14 | //! ```text |
| 15 | //! cc -o /tmp/abi-probe crates/ec-hw/abi-probe.c $(pkg-config --cflags libva) |
| 16 | //! ``` |
| 17 | //! |
| 18 | //! # Bit fields |
| 19 | //! |
| 20 | //! The C headers pack flags into `union { struct { uint32_t a : 2; ... } bits; |
| 21 | //! uint32_t value; }`. Rust has no bit fields, so each union becomes a |
| 22 | //! `#[repr(transparent)]` newtype over its storage integer with one chained |
| 23 | //! setter per flag, generated by [`va_bits`]. The System V ABI allocates |
| 24 | //! bit fields LSB first within the storage unit, which is what the generated |
| 25 | //! shifts assume — the one ABI assumption in this module that the probe cannot |
| 26 | //! see, and the reason every generated setter is exercised by a unit test. |
| 27 | |
| 28 | use Arc; |
| 29 | |
| 30 | use ; |
| 31 | use ; |
| 32 | |
| 33 | use crateResult; |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | /// A plain-old-data parameter struct libva reads verbatim. |
| 42 | /// |
| 43 | /// # Safety |
| 44 | /// |
| 45 | /// The implementing type must be a `#[repr(C)]` transcription of exactly the |
| 46 | /// libva struct that belongs to [`VaParam::TYPE`], with the same size and field |
| 47 | /// offsets (which is what the `const` assertions in this module check), and |
| 48 | /// must be valid for any bit pattern it is constructed with — the driver reads |
| 49 | /// `size_of::<Self>()` bytes of it, padding included. |
| 50 | pub unsafe |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | /// Create a VA buffer holding one parameter struct. |
| 56 | /// |
| 57 | /// This is the *only* place `ec-hw` hands a Rust value to the driver as bytes; |
| 58 | /// the [`VaParam`] bound is what makes it sound, and every implementation of |
| 59 | /// that trait sits next to the transcription it vouches for. |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | /// `VA_INVALID_SURFACE`, spelled out where a parameter struct means "no picture". |
| 69 | pub const INVALID_SURFACE: VASurfaceID = VA_INVALID_SURFACE; |
| 70 | |
| 71 | /// Generate a `#[repr(transparent)]` newtype standing in for a C bit field union. |
| 72 | /// |
| 73 | /// Fields are listed in header order with their widths; the generated setters |
| 74 | /// place them LSB first, which is how the System V ABI allocates `uint32_t` |
| 75 | /// bit fields. Each setter masks its value, so an out-of-range argument cannot |
| 76 | /// corrupt a neighbouring field. |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | ; |
| 97 | => ; |
| 98 | => |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | ; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 |