forge
Explore
Log in

Don't you dare go Hollow

U17: ec-va tests/gpu.rs trimmed to three live tests (caps table, P010 VPP convert, DMA-BUF round trip)

Browse files at this commit

5c7d6bf59180cb25409736fe0df621b932deaca5Ahmet Kaan GümüşParent: 5f59ead
crates/ec-va/tests/gpu.rsmodified+1 -385
@@ -9,14 +9,12 @@
99 //!
1010 //! Reference: `vainfo` on this box (Mesa 26.1.6, radeonsi gfx1200, RX 9060 XT).
1111
12-use std::os::fd::AsRawFd;
1312 use std::rc::Rc;
1413 use std::sync::{Mutex, MutexGuard, OnceLock};
15-use std::time::Duration;
1614
1715 use ec_va::caps::{Entrypoint, Profile};
1816 use ec_va::va;
19-use ec_va::{CapReport, Config, Display, Image, Surface, SurfaceExt, SurfaceSpec, create_pool};
17+use ec_va::{CapReport, Display, Image, Surface, SurfaceExt, SurfaceSpec, create_pool};
2018
2119 /// Runs the tests in this binary one at a time.
2220 ///
@@ -57,28 +55,6 @@ fn one(display: &Rc<Display>, spec: &SurfaceSpec) -> Surface {
5755
5856 // --------------------------------------------------------------------------
5957 // Display
60-// --------------------------------------------------------------------------
61-
62-// The raw `Display::version` / `device_path` / `is_valid` checks no longer
63-// exist in cros-libva; what remains observable is that the open succeeded and
64-// the driver answers real queries.
65-#[test]
66-fn display_opens_on_a_render_node() {
67- let _serial = serial();
68- let display = display();
69- let vendor = ec_va::display::vendor(&display).expect("vendor string");
70- assert!(!vendor.is_empty(), "driver reported an empty vendor string");
71- assert!(
72- !display
73- .query_config_profiles()
74- .expect("profiles")
75- .is_empty()
76- );
77-}
78-
79-// --------------------------------------------------------------------------
80-// Capabilities — the table must match `vainfo` on this GPU
81-// --------------------------------------------------------------------------
8258
8359 #[test]
8460 fn caps_match_vainfo_on_this_gpu() {
@@ -170,351 +146,6 @@ fn caps_match_vainfo_on_this_gpu() {
170146 );
171147 }
172148
173-#[test]
174-fn caps_report_driver_legal_surface_sizes() {
175- let _serial = serial();
176- let display = display();
177- let caps = CapReport::probe(&display).expect("probe");
178- let entry = caps
179- .entry(Profile::H264Main, Entrypoint::VLD)
180- .expect("H264 Main VLD");
181- let surfaces = entry.surfaces.as_ref().expect("surface caps");
182-
183- // radeonsi rejects decode surfaces below 64x64. Probing with a hardcoded
184- // 16x16 config is what used to panic here, so the minimum is reported
185- // rather than assumed.
186- assert_eq!(surfaces.min_width, Some(64));
187- assert_eq!(surfaces.min_height, Some(64));
188- assert!(surfaces.max_width.unwrap() >= 4096);
189- assert!(
190- !surfaces.allows(16, 16),
191- "16x16 must be refused by the caps"
192- );
193- assert!(surfaces.allows(1920, 1088));
194-
195- // DRM PRIME 2 export must be advertised: that is how frames leave the GPU.
196- assert!(
197- surfaces.memory_types & va::VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2 != 0,
198- "memory types 0x{:08x} lack DRM_PRIME_2",
199- surfaces.memory_types
200- );
201-}
202-
203-#[test]
204-fn unsupported_pair_is_refused_by_the_driver() {
205- let _serial = serial();
206- // A refusal is a claim: prove the capability is genuinely absent rather
207- // than assumed absent.
208- let display = display();
209- let caps = CapReport::probe(&display).expect("probe");
210- assert!(!caps.supports(Profile::VP9Profile1, Entrypoint::VLD));
211-
212- let err = Config::new(&display, Profile::VP9Profile1, Entrypoint::VLD, &[])
213- .err()
214- .expect("VP9 Profile1 decode does not exist on this GPU");
215- let status = err.status().expect("a VAStatus-carrying error");
216- assert!(
217- status == va::VA_STATUS_ERROR_UNSUPPORTED_PROFILE as i32
218- || status == va::VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT as i32,
219- "unexpected refusal: {err}"
220- );
221- assert!(err.to_string().contains("vaCreateConfig"), "{err}");
222-}
223-
224-// --------------------------------------------------------------------------
225-// Surfaces
226-// --------------------------------------------------------------------------
227-
228-#[test]
229-fn surface_pool_create_and_destroy_is_leak_free() {
230- let _serial = serial();
231- let display = display();
232- let spec = SurfaceSpec::nv12(64, 64);
233-
234- // Warm up so first-touch allocations are not counted as a leak.
235- for _ in 0..4 {
236- let p = pool(&display, &spec, 16);
237- assert_eq!(p.len(), 16);
238- drop(p);
239- }
240-
241- let before = vm_rss_kb();
242- for _ in 0..100 {
243- let p = pool(&display, &spec, 16);
244- // Every id must be distinct and valid, or the pool is aliasing memory.
245- let mut ids: Vec<_> = p.iter().map(|s| s.id()).collect();
246- ids.sort_unstable();
247- ids.dedup();
248- assert_eq!(ids.len(), 16, "vaCreateSurfaces returned duplicate ids");
249- assert!(ids.iter().all(|&id| id != va::VA_INVALID_SURFACE));
250- drop(p);
251- }
252- let after = vm_rss_kb();
253-
254- // 1600 surfaces created and destroyed. A per-surface leak would be obvious
255- // at this scale; the incumbent's unmatched map leaked ~3MB per frame.
256- let delta_kb = after.saturating_sub(before);
257- assert!(
258- delta_kb < 50 * 1024,
259- "VmRSS grew {delta_kb} kB over 100 create/destroy cycles"
260- );
261-}
262-
263-#[test]
264-fn derive_image_maps_and_reads_back() {
265- let _serial = serial();
266- let display = display();
267- let surface = one(&display, &SurfaceSpec::nv12(64, 64));
268- let mut image = Image::derive_from(&surface, (64, 64)).expect("vaDeriveImage");
269-
270- let va_image = *image.image();
271- assert_eq!(va_image.format.fourcc, va::VA_FOURCC_NV12);
272- assert_eq!(image.display_resolution(), (64, 64));
273- assert!(image.is_derived());
274- assert_eq!(va_image.num_planes, 2, "NV12 is luma + interleaved chroma");
275- let pitch = va_image.pitches[0] as usize;
276- assert!(pitch >= 64, "luma pitch {pitch} is narrower than the image");
277- assert!(va_image.pitches[1] > 0, "chroma pitch missing");
278- let luma_off = va_image.offsets[0] as usize;
279- let chroma_off = va_image.offsets[1] as usize;
280- assert!(
281- chroma_off >= luma_off + pitch * 64,
282- "luma plane must be at least pitch * height"
283- );
284-
285- {
286- let bytes: &mut [u8] = image.as_mut();
287- assert!(
288- bytes.len() > chroma_off,
289- "mapping shorter than chroma plane"
290- );
291- for (i, byte) in bytes[luma_off..luma_off + pitch * 64]
292- .iter_mut()
293- .enumerate()
294- {
295- *byte = (i % 251) as u8;
296- }
297- let luma = &bytes[luma_off..];
298- assert_eq!(luma[0], 0);
299- assert_eq!(luma[250], 250);
300- assert_eq!(luma[251], 0, "write did not survive within the mapping");
301- }
302- drop(image);
303-
304- // Re-deriving after the drop proves the unmap/destroy actually happened.
305- //
306- // What is deliberately *not* asserted: that the bytes written above are
307- // readable through this second mapping. On radeonsi 26.1 a derived-image
308- // mapping is write-oriented staging — the write reaches the surface (see
309- // `created_image_reads_a_surface_back`), but a fresh map reads back zeros.
310- let again = Image::derive_from(&surface, (64, 64)).expect("second vaDeriveImage");
311- assert_eq!(
312- again.image().pitches[0] as usize,
313- pitch,
314- "second mapping has a different geometry"
315- );
316- assert!(!AsRef::<[u8]>::as_ref(&again).is_empty());
317-}
318-
319-#[test]
320-fn created_image_reads_a_surface_back() {
321- let _serial = serial();
322- let display = display();
323- let surface = one(&display, &SurfaceSpec::nv12(64, 64));
324- // Paint through the derived image so there is something known to read back.
325- {
326- let mut derived = Image::derive_from(&surface, (64, 64)).expect("derive");
327- let luma_off = derived.image().offsets[0] as usize;
328- let pitch = derived.image().pitches[0] as usize;
329- let bytes: &mut [u8] = derived.as_mut();
330- for byte in &mut bytes[luma_off..luma_off + pitch * 64] {
331- *byte = 0x5a;
332- }
333- }
334- surface.sync().expect("sync");
335-
336- let fmt = image_format(&display, va::VA_FOURCC_NV12);
337- let image = Image::create_from(&surface, fmt, (64, 64), (64, 64)).expect("vaGetImage");
338- let luma_off = image.image().offsets[0] as usize;
339- let bytes: &[u8] = image.as_ref();
340- assert!(
341- bytes[luma_off..luma_off + 64].iter().all(|&b| b == 0x5a),
342- "vaGetImage did not return the painted luma"
343- );
344- drop(image);
345-
346- // A region larger than the surface must be refused, not read out of bounds.
347- let fmt = image_format(&display, va::VA_FOURCC_NV12);
348- let refused = Image::create_from(&surface, fmt, (128, 128), (128, 128));
349- assert!(
350- refused.is_err(),
351- "region larger than the surface must be refused"
352- );
353-}
354-
355-#[test]
356-fn prime_export_owns_and_releases_its_descriptors() {
357- let _serial = serial();
358- let display = display();
359- let surface = one(&display, &SurfaceSpec::nv12(64, 64));
360- surface
361- .sync_timeout(Duration::from_secs(5))
362- .expect("sync before export");
363-
364- let baseline = open_fd_count();
365- let exported = surface.export().expect("vaExportSurfaceHandle");
366-
367- assert_eq!(exported.fourcc, va::VA_FOURCC_NV12);
368- assert_eq!((exported.width, exported.height), (64, 64));
369- assert!(!exported.objects.is_empty(), "no DRM objects exported");
370- assert!(!exported.layers.is_empty(), "no layers exported");
371- for object in &exported.objects {
372- assert!(object.fd.as_raw_fd() >= 0);
373- assert!(object.size > 0);
374- }
375- for layer in &exported.layers {
376- assert!(!layer.planes.is_empty());
377- for &(object_index, _offset, pitch) in &layer.planes {
378- assert!((object_index as usize) < exported.objects.len());
379- assert!(pitch > 0);
380- }
381- }
382-
383- let with_export = open_fd_count();
384- assert_eq!(
385- with_export - baseline,
386- exported.objects.len(),
387- "exported fd count does not match the descriptor"
388- );
389- drop(exported);
390- assert_eq!(
391- open_fd_count(),
392- baseline,
393- "dropping the export leaked file descriptors"
394- );
395-}
396-
397-// --------------------------------------------------------------------------
398-// Context / picture protocol
399-// --------------------------------------------------------------------------
400-
401-#[test]
402-fn picture_typestate_walks_the_va_protocol() {
403- let _serial = serial();
404- let display = display();
405- let config = Config::new(&display, Profile::H264Main, Entrypoint::VLD, &[]).expect("config");
406- let targets = pool(&display, &SurfaceSpec::nv12(1920, 1088), 2);
407- let context = ec_va::create_context(&display, &config, 1920, 1088, Some(&targets), true)
408- .expect("context");
409- let targets: Vec<Rc<Surface>> = targets.into_iter().map(Rc::new).collect();
410-
411- // New -> Begin. Each transition consumes the picture, so nothing can call
412- // `begin` twice or reach `sync` without `end`.
413- let picture = ec_va::Picture::new(0, Rc::clone(&context), Rc::clone(&targets[0]));
414- let picture = picture.begin::<()>().expect("vaBeginPicture");
415- assert_eq!(picture.surface::<()>().id(), targets[0].id());
416-
417- // Begin -> Render -> End. Submitting a picture with no parameter buffers
418- // is a driver-level error here (mesa creates the decoder lazily from the
419- // picture parameters); what matters is that it surfaces as a typed error
420- // instead of a panic, an abort or a GPU hang. Real submissions carry
421- // parameter/slice buffers and are `ec-hw`'s job.
422- let failed = picture.render().and_then(|p| p.end());
423- let err = failed
424- .err()
425- .expect("empty submission is rejected by radeonsi");
426- assert_eq!(
427- err.va_status(),
428- va::VA_STATUS_ERROR_INVALID_CONTEXT as i32,
429- "{err}"
430- );
431-
432- // The display is still usable afterwards: an abandoned picture must not
433- // wedge the context.
434- let picture = ec_va::Picture::new(0, Rc::clone(&context), Rc::clone(&targets[1]))
435- .begin::<()>()
436- .expect("second vaBeginPicture after a failed end");
437- drop(picture);
438- assert!(display.query_vendor_string().is_ok());
439-}
440-
441-#[test]
442-fn buffers_map_unmap_and_destroy() {
443- let _serial = serial();
444- let display = display();
445- let config =
446- Config::new(&display, Profile::H264Main, Entrypoint::EncSlice, &[]).expect("config");
447- let targets = pool(&display, &SurfaceSpec::nv12(1920, 1088), 1);
448- let context = ec_va::create_context(&display, &config, 1920, 1088, Some(&targets), true)
449- .expect("context");
450-
451- // Coded-output buffer: allocated empty, mapped, unmapped, dropped.
452- const CODED_SIZE: usize = 1 << 20;
453- let coded = context
454- .create_enc_coded(CODED_SIZE)
455- .expect("vaCreateBuffer");
456- assert_ne!(coded.id(), va::VA_INVALID_ID);
457- {
458- let mapped = va::MappedCodedBuffer::new(&coded).expect("vaMapBuffer");
459- // Never filled by an encode: no segment carries payload bytes.
460- assert!(mapped.iter().all(|s| s.buf.is_empty()));
461- }
462- // Mapping again proves the guard released the mapping.
463- drop(va::MappedCodedBuffer::new(&coded).expect("second vaMapBuffer after unmap"));
464-
465- // Parameter buffer: data is copied into driver memory during the call.
466- let buffer = ec_va::picture::buffer(
467- &context,
468- va::BufferType::EncMiscParameter(va::EncMiscParameter::FrameRate(
469- va::EncMiscParameterFrameRate::new(30, 0),
470- )),
471- )
472- .expect("vaCreateBuffer from a typed parameter");
473- drop(buffer);
474- drop(coded);
475-}
476-
477-#[test]
478-fn context_keeps_its_dependencies_alive() {
479- let _serial = serial();
480- // Dropping the config and the surfaces while the context lives must be
481- // safe: the context holds `Rc`s, so libva's destruction order (buffers ->
482- // context -> surfaces -> config -> display) cannot be violated.
483- let display = display();
484- let config = Config::new(&display, Profile::H264Main, Entrypoint::VLD, &[]).expect("config");
485- let targets = pool(&display, &SurfaceSpec::nv12(1920, 1088), 2);
486- let context = ec_va::create_context(&display, &config, 1920, 1088, Some(&targets), true)
487- .expect("context");
488- let target = Rc::new(targets.into_iter().next().expect("target"));
489- drop(config);
490-
491- let picture = ec_va::Picture::new(0, Rc::clone(&context), target)
492- .begin::<()>()
493- .expect("begin");
494- drop(picture);
495- drop(context);
496- assert!(display.query_vendor_string().is_ok());
497-}
498-
499-// --------------------------------------------------------------------------
500-// VPP
501-// --------------------------------------------------------------------------
502-
503-// `vaQueryVideoProcFilters` is no longer wrapped (cros-libva has no such
504-// call), so the filter list cannot be printed. The equivalent: a pipeline
505-// still opens on the real display and runs a whole-surface NV12 pass.
506-#[test]
507-fn vpp_filters_probe() {
508- let _serial = serial();
509- let display = display();
510- let targets = pool(&display, &SurfaceSpec::nv12(1920, 1080), 2);
511- let vpp = ec_va::Vpp::new(&display, va::VA_RT_FORMAT_YUV420, 1920, 1080).expect("vpp opens");
512- let mut it = targets.into_iter();
513- let src = it.next().expect("src");
514- let dst = Rc::new(it.next().expect("dst"));
515- vpp.convert(&src, dst).expect("vpp pipeline runs");
516-}
517-
518149 /// `Vpp::convert` end to end: a P010 source surface into an NV12 destination,
519150 /// no readback — the conversion `ec-hw`'s `encode_frame` relies on for a
520151 /// 10-bit source.
@@ -537,21 +168,6 @@ fn vpp_converts_p010_to_nv12() {
537168
538169 // --------------------------------------------------------------------------
539170 // helpers
540-// --------------------------------------------------------------------------
541-
542-fn vm_rss_kb() -> u64 {
543- let status = std::fs::read_to_string("/proc/self/status").expect("/proc/self/status");
544- for line in status.lines() {
545- if let Some(rest) = line.strip_prefix("VmRSS:") {
546- return rest
547- .split_whitespace()
548- .next()
549- .and_then(|v| v.parse().ok())
550- .expect("VmRSS value");
551- }
552- }
553- panic!("VmRSS not found in /proc/self/status");
554-}
555171
556172 fn open_fd_count() -> usize {
557173 std::fs::read_dir("/proc/self/fd")