forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB7cdaf34Tahinli3 months ago29 commits

sys.rs558 lines, 20.9 KiBHistoryRawDownload
1//! Hand-written FFI for the subset of libva this family uses.
2//!
3//! # Why hand-written
4//!
5//! No `bindgen`: the family rule is no build-time tooling, and a generated
6//! 40k-line binding hides exactly the thing that has to be audited — the ABI
7//! assumptions. Everything here is transcribed from the system headers and is
8//! short enough to read in one sitting.
9//!
10//! # ABI assumptions (all four are load-bearing)
11//!
12//! 1. **libva 1.23.0 headers**, `/usr/include/va/{va.h,va_drm.h,va_drmcommon.h}`,
13//! target `x86_64-unknown-linux-gnu`, System V C ABI.
14//! 2. **C `enum` is `int` (4 bytes)** on this ABI. Every VA enum is transcribed
15//! as a plain `i32` type alias plus constants, *never* as a `#[repr(i32)]`
16//! Rust enum: the driver writes profile/entrypoint values into buffers we
17//! own, and a value we have no variant for would be instant UB on a real
18//! Rust enum. Interpretation happens in the safe layer
19//! ([`crate::caps::Profile::from_raw`]), which has an `Unknown(i32)` arm.
20//! This is the header-drift trap that broke cros-libva at libva >= 1.23.
21//! 3. **Struct layouts** below are checked by the `const _: () = assert!(...)`
22//! block at the end of this file against numbers printed by
23//! `crates/ec-va/abi-probe.c` compiled against the *system* headers. Rerun
24//! that probe after a libva upgrade; a mismatch means this file drifted.
25//! 4. **`VADisplay` is an opaque pointer**; we never dereference it.
26//!
27//! Points 1-3 are compile-time. They cannot see a libva that changes layout
28//! *after* this crate is built, so [`crate::Display::open`] additionally
29//! performs a **runtime** `vaInitialize` version check and refuses anything
30//! older than 1.23 with a typed error.
31
32// Every item keeps its exact C spelling so that this file can be diffed
33// against the headers by eye — the whole audit story of a hand-written FFI.
34#![allow(non_camel_case_types)]
35#![allow(non_snake_case)]
36#![allow(non_upper_case_globals)]
37// Fields keep their C names and are documented by the header line cited on
38// each item; restating "the fourcc field is the fourcc" 60 times would bury
39// the ABI notes that actually matter here.
40#![allow(missing_docs)]
41
42use std::ffi::{c_char, c_int, c_uint, c_void};
43
44// ---------------------------------------------------------------------------
45// Scalar types (va.h:260-262, 1580-1647, 2042, 4727)
46// ---------------------------------------------------------------------------
47
48/// Opaque display handle. Never dereferenced by this crate.
49pub type VADisplay = *mut c_void;
50/// Return status of every VA entry point. `va.h:262`.
51pub type VAStatus = i32;
52/// `va.h:1580`.
53pub type VAGenericID = c_uint;
54pub type VAConfigID = VAGenericID;
55pub type VAContextID = VAGenericID;
56pub type VASurfaceID = VAGenericID;
57pub type VABufferID = VAGenericID;
58pub type VAImageID = VAGenericID;
59
60/// C enum `VAProfile` (`va.h:502`), kept as `i32`. See ABI assumption 2.
61pub type VAProfile = i32;
62/// C enum `VAEntrypoint` (`va.h:552`), kept as `i32`.
63pub type VAEntrypoint = i32;
64/// C enum `VAConfigAttribType` (`va.h:619`), kept as `i32`.
65pub type VAConfigAttribType = i32;
66/// C enum `VASurfaceAttribType` (`va.h:1689`), kept as `i32`.
67pub type VASurfaceAttribType = i32;
68/// C enum `VAGenericValueType` (`va.h:1651`), kept as `i32`.
69pub type VAGenericValueType = i32;
70/// C enum `VABufferType` (`va.h:2044`), kept as `i32`.
71pub type VABufferType = i32;
72
73pub const VA_INVALID_ID: VAGenericID = 0xffff_ffff;
74pub const VA_INVALID_SURFACE: VASurfaceID = VA_INVALID_ID;
75
76// Status codes actually branched on; the rest are reported via `vaErrorStr`.
77// `va.h:264-309`.
78pub const VA_STATUS_SUCCESS: VAStatus = 0x0000_0000;
79pub const VA_STATUS_ERROR_INVALID_CONTEXT: VAStatus = 0x0000_0005;
80pub const VA_STATUS_ERROR_UNSUPPORTED_PROFILE: VAStatus = 0x0000_000c;
81pub const VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT: VAStatus = 0x0000_000d;
82pub const VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT: VAStatus = 0x0000_000e;
83pub const VA_STATUS_ERROR_MAX_NUM_EXCEEDED: VAStatus = 0x0000_000b;
84pub const VA_STATUS_ERROR_UNIMPLEMENTED: VAStatus = 0x0000_0014;
85pub const VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED: VAStatus = 0x0000_0013;
86pub const VA_STATUS_ERROR_OPERATION_FAILED: VAStatus = 0x0000_0001;
87pub const VA_STATUS_ERROR_INVALID_PARAMETER: VAStatus = 0x0000_0012;
88
89// Entrypoints (`va.h:552`).
90pub const VAEntrypointVLD: VAEntrypoint = 1;
91pub const VAEntrypointEncSlice: VAEntrypoint = 6;
92pub const VAEntrypointEncPicture: VAEntrypoint = 7;
93pub const VAEntrypointEncSliceLP: VAEntrypoint = 8;
94pub const VAEntrypointVideoProc: VAEntrypoint = 10;
95
96// Config attribute types (`va.h:619`).
97pub const VAConfigAttribRTFormat: VAConfigAttribType = 0;
98pub const VAConfigAttribRateControl: VAConfigAttribType = 5;
99pub const VAConfigAttribDecSliceMode: VAConfigAttribType = 6;
100pub const VAConfigAttribEncPackedHeaders: VAConfigAttribType = 10;
101
102// RT formats (`va.h:1073-1090`).
103pub const VA_RT_FORMAT_YUV420: u32 = 0x0000_0001;
104pub const VA_RT_FORMAT_YUV422: u32 = 0x0000_0002;
105pub const VA_RT_FORMAT_YUV444: u32 = 0x0000_0004;
106pub const VA_RT_FORMAT_YUV400: u32 = 0x0000_0010;
107pub const VA_RT_FORMAT_YUV420_10: u32 = 0x0000_0100;
108pub const VA_RT_FORMAT_YUV422_10: u32 = 0x0000_0200;
109pub const VA_RT_FORMAT_YUV444_10: u32 = 0x0000_0400;
110pub const VA_RT_FORMAT_YUV420_12: u32 = 0x0000_1000;
111pub const VA_RT_FORMAT_RGB32: u32 = 0x0002_0000;
112
113// Surface attribute types (`va.h:1689`) and flags (`va.h:1681-1684`).
114pub const VASurfaceAttribNone: VASurfaceAttribType = 0;
115pub const VASurfaceAttribPixelFormat: VASurfaceAttribType = 1;
116pub const VASurfaceAttribMinWidth: VASurfaceAttribType = 2;
117pub const VASurfaceAttribMaxWidth: VASurfaceAttribType = 3;
118pub const VASurfaceAttribMinHeight: VASurfaceAttribType = 4;
119pub const VASurfaceAttribMaxHeight: VASurfaceAttribType = 5;
120pub const VASurfaceAttribMemoryType: VASurfaceAttribType = 6;
121pub const VASurfaceAttribUsageHint: VASurfaceAttribType = 8;
122
123pub const VA_SURFACE_ATTRIB_GETTABLE: u32 = 0x0000_0001;
124pub const VA_SURFACE_ATTRIB_SETTABLE: u32 = 0x0000_0002;
125
126pub const VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC: u32 = 0x0000_0000;
127pub const VA_SURFACE_ATTRIB_USAGE_HINT_DECODER: u32 = 0x0000_0001;
128pub const VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER: u32 = 0x0000_0002;
129pub const VA_SURFACE_ATTRIB_USAGE_HINT_EXPORT: u32 = 0x0000_0020;
130
131// Generic value discriminants (`va.h:1651`).
132pub const VAGenericValueTypeInteger: VAGenericValueType = 1;
133pub const VAGenericValueTypeFloat: VAGenericValueType = 2;
134pub const VAGenericValueTypePointer: VAGenericValueType = 3;
135pub const VAGenericValueTypeFunc: VAGenericValueType = 4;
136
137// Buffer types actually used by decode/encode paths (`va.h:2044`).
138pub const VAPictureParameterBufferType: VABufferType = 0;
139pub const VAIQMatrixBufferType: VABufferType = 1;
140pub const VASliceParameterBufferType: VABufferType = 4;
141pub const VASliceDataBufferType: VABufferType = 5;
142pub const VAImageBufferType: VABufferType = 9;
143pub const VAProbabilityBufferType: VABufferType = 13;
144pub const VAEncCodedBufferType: VABufferType = 21;
145pub const VAEncSequenceParameterBufferType: VABufferType = 22;
146pub const VAEncPictureParameterBufferType: VABufferType = 23;
147pub const VAEncSliceParameterBufferType: VABufferType = 24;
148pub const VAEncPackedHeaderParameterBufferType: VABufferType = 25;
149pub const VAEncPackedHeaderDataBufferType: VABufferType = 26;
150pub const VAEncMiscParameterBufferType: VABufferType = 27;
151
152/// `vaCreateContext` flag: sequence contains only progressive frames (`va.h:1919`).
153pub const VA_PROGRESSIVE: c_int = 0x1;
154
155// DRM PRIME memory types and export flags (`va_drmcommon.h:78-94`, `va.h:4130-4150`).
156pub const VA_SURFACE_ATTRIB_MEM_TYPE_VA: u32 = 0x0000_0001;
157pub const VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM: u32 = 0x1000_0000;
158pub const VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: u32 = 0x2000_0000;
159pub const VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2: u32 = 0x4000_0000;
160
161pub const VA_EXPORT_SURFACE_READ_ONLY: u32 = 0x0001;
162pub const VA_EXPORT_SURFACE_WRITE_ONLY: u32 = 0x0002;
163pub const VA_EXPORT_SURFACE_READ_WRITE: u32 = 0x0003;
164pub const VA_EXPORT_SURFACE_SEPARATE_LAYERS: u32 = 0x0004;
165pub const VA_EXPORT_SURFACE_COMPOSED_LAYERS: u32 = 0x0008;
166
167// FourCCs used by the family (`va.h:4400-4700`).
168pub const VA_FOURCC_NV12: u32 = 0x3231_564e;
169pub const VA_FOURCC_P010: u32 = 0x3031_3050;
170pub const VA_FOURCC_I420: u32 = 0x3032_3449;
171pub const VA_FOURCC_YV12: u32 = 0x3231_5659;
172
173// ---------------------------------------------------------------------------
174// Structs
175// ---------------------------------------------------------------------------
176
177/// `VAConfigAttrib`, `va.h:1155`.
178#[repr(C)]
179#[derive(Debug, Clone, Copy, PartialEq, Eq)]
180pub struct VAConfigAttrib {
181 pub type_: VAConfigAttribType,
182 pub value: u32,
183}
184
185/// The `value` union of `VAGenericValue`, `va.h:1663-1673`.
186///
187/// Only ever read after checking the sibling `type_` discriminant.
188#[repr(C)]
189#[derive(Clone, Copy)]
190pub union VAGenericValueUnion {
191 pub i: i32,
192 pub f: f32,
193 pub p: *mut c_void,
194 pub func: Option<extern "C" fn()>,
195}
196
197/// `VAGenericValue`, `va.h:1661`.
198#[repr(C)]
199#[derive(Clone, Copy)]
200pub struct VAGenericValue {
201 pub type_: VAGenericValueType,
202 pub value: VAGenericValueUnion,
203}
204
205/// `VASurfaceAttrib`, `va.h:1741`.
206#[repr(C)]
207#[derive(Clone, Copy)]
208pub struct VASurfaceAttrib {
209 pub type_: VASurfaceAttribType,
210 pub flags: u32,
211 pub value: VAGenericValue,
212}
213
214/// `VAImageFormat`, `va.h:4712`. `va_reserved` is `VA_PADDING_LOW` = 4 u32s.
215#[repr(C)]
216#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
217pub struct VAImageFormat {
218 pub fourcc: u32,
219 pub byte_order: u32,
220 pub bits_per_pixel: u32,
221 pub depth: u32,
222 pub red_mask: u32,
223 pub green_mask: u32,
224 pub blue_mask: u32,
225 pub alpha_mask: u32,
226 pub va_reserved: [u32; 4],
227}
228
229/// `VAImage`, `va.h:4729`.
230#[repr(C)]
231#[derive(Debug, Clone, Copy)]
232pub struct VAImage {
233 pub image_id: VAImageID,
234 pub format: VAImageFormat,
235 pub buf: VABufferID,
236 pub width: u16,
237 pub height: u16,
238 pub data_size: u32,
239 pub num_planes: u32,
240 pub pitches: [u32; 3],
241 pub offsets: [u32; 3],
242 pub num_palette_entries: i32,
243 pub entry_bytes: i32,
244 pub component_order: [i8; 4],
245 pub va_reserved: [u32; 4],
246}
247
248impl Default for VAImage {
249 fn default() -> Self {
250 // All-zero is a valid "not yet filled" VAImage; `image_id` is
251 // overwritten by vaDeriveImage/vaCreateImage before any use.
252 // SAFETY: every field is a plain integer or array of integers, so the
253 // all-zero bit pattern is a valid value of this type.
254 unsafe { std::mem::zeroed() }
255 }
256}
257
258/// One DRM object of a `VADRMPRIMESurfaceDescriptor`, `va_drmcommon.h:139-147`.
259#[repr(C)]
260#[derive(Debug, Clone, Copy)]
261pub struct VADRMPRIMEObject {
262 pub fd: c_int,
263 pub size: u32,
264 pub drm_format_modifier: u64,
265}
266
267/// One layer of a `VADRMPRIMESurfaceDescriptor`, `va_drmcommon.h:151-164`.
268#[repr(C)]
269#[derive(Debug, Clone, Copy)]
270pub struct VADRMPRIMELayer {
271 pub drm_format: u32,
272 pub num_planes: u32,
273 pub object_index: [u32; 4],
274 pub offset: [u32; 4],
275 pub pitch: [u32; 4],
276}
277
278/// `VADRMPRIMESurfaceDescriptor`, `va_drmcommon.h:130`. Used with
279/// [`VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2`].
280#[repr(C)]
281#[derive(Debug, Clone, Copy)]
282pub struct VADRMPRIMESurfaceDescriptor {
283 pub fourcc: u32,
284 pub width: u32,
285 pub height: u32,
286 pub num_objects: u32,
287 pub objects: [VADRMPRIMEObject; 4],
288 pub num_layers: u32,
289 pub layers: [VADRMPRIMELayer; 4],
290}
291
292impl Default for VADRMPRIMESurfaceDescriptor {
293 fn default() -> Self {
294 // SAFETY: all fields are integers or arrays of integer structs; the
295 // all-zero bit pattern is valid. `fd` = 0 is never treated as an owned
296 // descriptor because `num_objects` = 0 in that state.
297 unsafe { std::mem::zeroed() }
298 }
299}
300
301/// `VARectangle`, `va.h:406`.
302#[repr(C)]
303#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
304pub struct VARectangle {
305 pub x: i16,
306 pub y: i16,
307 pub width: u16,
308 pub height: u16,
309}
310
311// ---------------------------------------------------------------------------
312// Entry points
313// ---------------------------------------------------------------------------
314
315#[link(name = "va")]
316unsafe extern "C" {
317 /// `va.h:403`. Returns a pointer to a static string; never NULL.
318 pub fn vaErrorStr(error_status: VAStatus) -> *const c_char;
319 /// `va.h:453`.
320 pub fn vaDisplayIsValid(dpy: VADisplay) -> c_int;
321 /// `va.h:465`.
322 pub fn vaInitialize(
323 dpy: VADisplay,
324 major_version: *mut c_int,
325 minor_version: *mut c_int,
326 ) -> VAStatus;
327 /// `va.h:474`.
328 pub fn vaTerminate(dpy: VADisplay) -> VAStatus;
329 /// `va.h:486`. Static string owned by the driver, valid until `vaTerminate`.
330 pub fn vaQueryVendorString(dpy: VADisplay) -> *const c_char;
331
332 /// `va.h:1524`.
333 pub fn vaMaxNumProfiles(dpy: VADisplay) -> c_int;
334 /// `va.h:1529`.
335 pub fn vaMaxNumEntrypoints(dpy: VADisplay) -> c_int;
336 /// `va.h:1534`.
337 pub fn vaMaxNumConfigAttributes(dpy: VADisplay) -> c_int;
338 /// `va.h:1544`.
339 pub fn vaQueryConfigProfiles(
340 dpy: VADisplay,
341 profile_list: *mut VAProfile,
342 num_profiles: *mut c_int,
343 ) -> VAStatus;
344 /// `va.h:1556`.
345 pub fn vaQueryConfigEntrypoints(
346 dpy: VADisplay,
347 profile: VAProfile,
348 entrypoint_list: *mut VAEntrypoint,
349 num_entrypoints: *mut c_int,
350 ) -> VAStatus;
351 /// `va.h:1571`. `attrib_list` is in/out: caller sets `type_`, driver fills `value`.
352 pub fn vaGetConfigAttributes(
353 dpy: VADisplay,
354 profile: VAProfile,
355 entrypoint: VAEntrypoint,
356 attrib_list: *mut VAConfigAttrib,
357 num_attribs: c_int,
358 ) -> VAStatus;
359 /// `va.h:1589`.
360 pub fn vaCreateConfig(
361 dpy: VADisplay,
362 profile: VAProfile,
363 entrypoint: VAEntrypoint,
364 attrib_list: *mut VAConfigAttrib,
365 num_attribs: c_int,
366 config_id: *mut VAConfigID,
367 ) -> VAStatus;
368 /// `va.h:1601`.
369 pub fn vaDestroyConfig(dpy: VADisplay, config_id: VAConfigID) -> VAStatus;
370
371 /// `va.h:1868`. Pass NULL `attrib_list` to only query the count.
372 pub fn vaQuerySurfaceAttributes(
373 dpy: VADisplay,
374 config: VAConfigID,
375 attrib_list: *mut VASurfaceAttrib,
376 num_attribs: *mut c_uint,
377 ) -> VAStatus;
378 /// `va.h:1894`.
379 pub fn vaCreateSurfaces(
380 dpy: VADisplay,
381 format: c_uint,
382 width: c_uint,
383 height: c_uint,
384 surfaces: *mut VASurfaceID,
385 num_surfaces: c_uint,
386 attrib_list: *mut VASurfaceAttrib,
387 num_attribs: c_uint,
388 ) -> VAStatus;
389 /// `va.h:1914`.
390 pub fn vaDestroySurfaces(
391 dpy: VADisplay,
392 surfaces: *mut VASurfaceID,
393 num_surfaces: c_int,
394 ) -> VAStatus;
395 /// `va.h:4185`. `descriptor` type is chosen by `mem_type`.
396 pub fn vaExportSurfaceHandle(
397 dpy: VADisplay,
398 surface_id: VASurfaceID,
399 mem_type: u32,
400 flags: u32,
401 descriptor: *mut c_void,
402 ) -> VAStatus;
403
404 /// `va.h:1933`.
405 pub fn vaCreateContext(
406 dpy: VADisplay,
407 config_id: VAConfigID,
408 picture_width: c_int,
409 picture_height: c_int,
410 flag: c_int,
411 render_targets: *mut VASurfaceID,
412 num_render_targets: c_int,
413 context: *mut VAContextID,
414 ) -> VAStatus;
415 /// `va.h:1949`.
416 pub fn vaDestroyContext(dpy: VADisplay, context: VAContextID) -> VAStatus;
417
418 /// `va.h:3833`. `data` NULL means "allocate, fill later via vaMapBuffer".
419 pub fn vaCreateBuffer(
420 dpy: VADisplay,
421 context: VAContextID,
422 type_: VABufferType,
423 size: c_uint,
424 num_elements: c_uint,
425 data: *mut c_void,
426 buf_id: *mut VABufferID,
427 ) -> VAStatus;
428 /// `va.h:3971`.
429 pub fn vaMapBuffer(dpy: VADisplay, buf_id: VABufferID, pbuf: *mut *mut c_void) -> VAStatus;
430 /// `va.h:4004`.
431 pub fn vaUnmapBuffer(dpy: VADisplay, buf_id: VABufferID) -> VAStatus;
432 /// `va.h:4018`.
433 pub fn vaDestroyBuffer(dpy: VADisplay, buffer_id: VABufferID) -> VAStatus;
434
435 /// `va.h:4205`.
436 pub fn vaBeginPicture(
437 dpy: VADisplay,
438 context: VAContextID,
439 render_target: VASurfaceID,
440 ) -> VAStatus;
441 /// `va.h:4214`.
442 pub fn vaRenderPicture(
443 dpy: VADisplay,
444 context: VAContextID,
445 buffers: *mut VABufferID,
446 num_buffers: c_int,
447 ) -> VAStatus;
448 /// `va.h:4229`.
449 pub fn vaEndPicture(dpy: VADisplay, context: VAContextID) -> VAStatus;
450 /// `va.h:4271`. Blocks until the render target is idle.
451 pub fn vaSyncSurface(dpy: VADisplay, render_target: VASurfaceID) -> VAStatus;
452
453 /// `va.h:4773`.
454 pub fn vaMaxNumImageFormats(dpy: VADisplay) -> c_int;
455 /// `va.h:4783`.
456 pub fn vaQueryImageFormats(
457 dpy: VADisplay,
458 format_list: *mut VAImageFormat,
459 num_formats: *mut c_int,
460 ) -> VAStatus;
461 /// `va.h:4796`.
462 pub fn vaCreateImage(
463 dpy: VADisplay,
464 format: *mut VAImageFormat,
465 width: c_int,
466 height: c_int,
467 image: *mut VAImage,
468 ) -> VAStatus;
469 /// `va.h:4807`.
470 pub fn vaDestroyImage(dpy: VADisplay, image: VAImageID) -> VAStatus;
471 /// `va.h:4827`.
472 pub fn vaGetImage(
473 dpy: VADisplay,
474 surface: VASurfaceID,
475 x: c_int,
476 y: c_int,
477 width: c_uint,
478 height: c_uint,
479 image: VAImageID,
480 ) -> VAStatus;
481 /// `va.h:4888`. Zero-copy view of a surface, when the driver allows it.
482 pub fn vaDeriveImage(dpy: VADisplay, surface: VASurfaceID, image: *mut VAImage) -> VAStatus;
483}
484
485#[link(name = "va-drm")]
486unsafe extern "C" {
487 /// `va_drm.h:45`. Returns NULL on failure. Does **not** take ownership of `fd`.
488 pub fn vaGetDisplayDRM(fd: c_int) -> VADisplay;
489}
490
491// ---------------------------------------------------------------------------
492// ABI transcription check
493// ---------------------------------------------------------------------------
494//
495// Reference output of `crates/ec-va/abi-probe.c` compiled against
496// /usr/include/va (libva 1.23.0) with gcc on x86_64:
497//
498// VAConfigAttrib size=8 align=4 type=0 value=4
499// VAGenericValue size=16 align=8 type=0 value=8
500// VASurfaceAttrib size=24 align=8 type=0 flags=4 value=8
501// VAImageFormat size=48 align=4 fourcc=0 .. va_reserved=32
502// VAImage size=120 align=4 image_id=0 format=4 buf=52
503// width=56 height=58 data_size=60
504// num_planes=64 pitches=68 offsets=80
505// num_palette_entries=92 entry_bytes=96
506// component_order=100 va_reserved=104
507// VADRMPRIMESurfaceDescriptor size=312 align=8 fourcc=0 width=4 height=8
508// num_objects=12 objects=16
509// num_layers=80 layers=84
510// object elem size=16, layer elem size=56
511// VARectangle size=8 align=2
512const _: () = {
513 use std::mem::{align_of, offset_of, size_of};
514
515 assert!(size_of::<VAConfigAttrib>() == 8 && align_of::<VAConfigAttrib>() == 4);
516 assert!(offset_of!(VAConfigAttrib, value) == 4);
517
518 assert!(size_of::<VAGenericValue>() == 16 && align_of::<VAGenericValue>() == 8);
519 assert!(offset_of!(VAGenericValue, value) == 8);
520
521 assert!(size_of::<VASurfaceAttrib>() == 24 && align_of::<VASurfaceAttrib>() == 8);
522 assert!(offset_of!(VASurfaceAttrib, flags) == 4);
523 assert!(offset_of!(VASurfaceAttrib, value) == 8);
524
525 assert!(size_of::<VAImageFormat>() == 48 && align_of::<VAImageFormat>() == 4);
526 assert!(offset_of!(VAImageFormat, va_reserved) == 32);
527
528 assert!(size_of::<VAImage>() == 120 && align_of::<VAImage>() == 4);
529 assert!(offset_of!(VAImage, format) == 4);
530 assert!(offset_of!(VAImage, buf) == 52);
531 assert!(offset_of!(VAImage, width) == 56);
532 assert!(offset_of!(VAImage, height) == 58);
533 assert!(offset_of!(VAImage, data_size) == 60);
534 assert!(offset_of!(VAImage, num_planes) == 64);
535 assert!(offset_of!(VAImage, pitches) == 68);
536 assert!(offset_of!(VAImage, offsets) == 80);
537 assert!(offset_of!(VAImage, num_palette_entries) == 92);
538 assert!(offset_of!(VAImage, entry_bytes) == 96);
539 assert!(offset_of!(VAImage, component_order) == 100);
540 assert!(offset_of!(VAImage, va_reserved) == 104);
541
542 assert!(size_of::<VADRMPRIMEObject>() == 16);
543 assert!(size_of::<VADRMPRIMELayer>() == 56);
544 assert!(
545 size_of::<VADRMPRIMESurfaceDescriptor>() == 312
546 && align_of::<VADRMPRIMESurfaceDescriptor>() == 8
547 );
548 assert!(offset_of!(VADRMPRIMESurfaceDescriptor, objects) == 16);
549 assert!(offset_of!(VADRMPRIMESurfaceDescriptor, num_layers) == 80);
550 assert!(offset_of!(VADRMPRIMESurfaceDescriptor, layers) == 84);
551
552 assert!(size_of::<VARectangle>() == 8 && align_of::<VARectangle>() == 2);
553
554 // Assumption 2: C `enum` and `unsigned int` are both 4 bytes here.
555 assert!(size_of::<VAStatus>() == 4);
556 assert!(size_of::<VAGenericID>() == 4);
557 assert!(size_of::<c_int>() == 4);
558};