forge
Explore
Log in

Don't you dare go Hollow

Merge parity/reset branch

Browse files at this commit

9777d9a292d408c088526c0b61d6ccfbad740bb2Ahmet Kaan GümüşParent: 2134128ca831ce
crates/ec-hw/examples/hw_parity.rsadded+466 -0
@@ -0,0 +1,466 @@
1+//! Vulkan Video against VA-API on the same clips: H.264, HEVC and AV1 encode at three CQP and three CBR points, reporting bytes, kbps, PSNR-Y against the source and encode ms/frame; then decode ms/frame of the CBR 3 Mb/s streams with both decoders.
2+//!
3+//! Every encode and decode runs in a child process of this binary, because the driver's state outlives a display: within one process the same encode lands at different sizes depending on what ran before it.
4+//!
5+//! ```text
6+//! cargo run --release -p ec-hw --example hw_parity -- <scratch dir>
7+//! ```
8+
9+use std::fmt::Display;
10+use std::fs;
11+use std::os::unix::fs::FileExt;
12+use std::path::{Path, PathBuf};
13+use std::process::Command;
14+use std::time::Instant;
15+
16+use ec_hw::{
17+ Backend, Codec, EncCodec, EncoderConfig, FrameMetadata, HwDecoder, HwEncoder, I420,
18+ RateControlMode,
19+};
20+
21+const FRAMES: usize = 60;
22+const FPS: u32 = 30;
23+const GOP: u32 = 30;
24+const SIZES: [(u32, u32); 2] = [(1280, 720), (1920, 1080)];
25+const SOURCES: [&str; 2] = ["testsrc2", "mandelbrot"];
26+const CBR: [u32; 3] = [1_000_000, 3_000_000, 6_000_000];
27+const DECODE_BITRATE: u32 = 3_000_000;
28+const JOB: &str = "HW_PARITY_JOB";
29+
30+#[derive(Clone, Copy)]
31+enum Mode {
32+ Cqp(u32),
33+ Cbr(u32),
34+}
35+
36+impl Mode {
37+ fn label(self) -> String {
38+ match self {
39+ Mode::Cqp(qp) => format!("CQP {qp}"),
40+ Mode::Cbr(bps) => format!("CBR {}M", bps / 1_000_000),
41+ }
42+ }
43+
44+ fn env(self) -> (&'static str, u32) {
45+ match self {
46+ Mode::Cqp(qp) => ("cqp", qp),
47+ Mode::Cbr(bps) => ("cbr", bps),
48+ }
49+ }
50+}
51+
52+#[derive(Clone, Copy)]
53+struct Spec {
54+ name: &'static str,
55+ key: &'static str,
56+ format: &'static str,
57+ enc: EncCodec,
58+ dec: Codec,
59+}
60+
61+const SPECS: [Spec; 3] = [
62+ Spec {
63+ name: "H.264",
64+ key: "h264",
65+ format: "h264",
66+ enc: EncCodec::H264,
67+ dec: Codec::H264,
68+ },
69+ Spec {
70+ name: "HEVC",
71+ key: "hevc",
72+ format: "hevc",
73+ enc: EncCodec::H265,
74+ dec: Codec::H265,
75+ },
76+ Spec {
77+ name: "AV1",
78+ key: "av1",
79+ format: "obu",
80+ enc: EncCodec::Av1,
81+ dec: Codec::Av1,
82+ },
83+];
84+
85+fn modes(spec: Spec) -> Vec<Mode> {
86+ let qps = if spec.key == "av1" {
87+ [110, 135, 160]
88+ } else {
89+ [22, 27, 32]
90+ };
91+ qps.into_iter()
92+ .map(Mode::Cqp)
93+ .chain(CBR.into_iter().map(Mode::Cbr))
94+ .collect()
95+}
96+
97+fn backend_key(backend: Backend) -> &'static str {
98+ match backend {
99+ Backend::Vk => "vk",
100+ Backend::Va => "va",
101+ }
102+}
103+
104+fn backend_from_key(key: &str) -> Backend {
105+ match key {
106+ "vk" => Backend::Vk,
107+ _ => Backend::Va,
108+ }
109+}
110+
111+fn spec_from_key(key: &str) -> Spec {
112+ *SPECS.iter().find(|s| s.key == key).expect("known codec key")
113+}
114+
115+fn make_source(dir: &Path, source: &str, w: u32, h: u32) -> PathBuf {
116+ let path = dir.join(format!("{source}-{w}x{h}.yuv"));
117+ if !path.exists() {
118+ let status = Command::new("ffmpeg")
119+ .args(["-nostdin", "-v", "error", "-y", "-f", "lavfi", "-i"])
120+ .arg(format!("{source}=size={w}x{h}:rate={FPS}"))
121+ .args(["-frames:v", &FRAMES.to_string(), "-pix_fmt", "yuv420p", "-f", "rawvideo"])
122+ .arg(&path)
123+ .status()
124+ .expect("run ffmpeg");
125+ assert!(status.success(), "ffmpeg cannot generate {source}");
126+ }
127+ path
128+}
129+
130+fn read_frames(path: &Path, w: u32, h: u32) -> Vec<I420> {
131+ let (wu, hu) = (w as usize, h as usize);
132+ let (cw, ch) = (wu / 2, hu / 2);
133+ let file = fs::File::open(path).expect("source clip");
134+ (0..FRAMES as u64)
135+ .map(|t| {
136+ let len = wu * hu + 2 * cw * ch;
137+ let mut buf = vec![0u8; len];
138+ file.read_exact_at(&mut buf, t * len as u64)
139+ .expect("read picture");
140+ let (y, rest) = buf.split_at(wu * hu);
141+ let (u, v) = rest.split_at(cw * ch);
142+ I420 {
143+ y: y.to_vec(),
144+ u: u.to_vec(),
145+ v: v.to_vec(),
146+ width: w,
147+ height: h,
148+ }
149+ })
150+ .collect()
151+}
152+
153+fn write_aus(path: &Path, aus: &[Vec<u8>]) {
154+ let mut out = Vec::new();
155+ for au in aus {
156+ out.extend_from_slice(&(au.len() as u32).to_le_bytes());
157+ out.extend_from_slice(au);
158+ }
159+ fs::write(path, out).expect("write access units");
160+}
161+
162+fn read_aus(path: &Path) -> Vec<Vec<u8>> {
163+ let data = fs::read(path).expect("read access units");
164+ let mut aus = Vec::new();
165+ let mut at = 0;
166+ while at + 4 <= data.len() {
167+ let len = u32::from_le_bytes(data[at..at + 4].try_into().expect("4 bytes")) as usize;
168+ aus.push(data[at + 4..at + 4 + len].to_vec());
169+ at += 4 + len;
170+ }
171+ aus
172+}
173+
174+fn or_exit<T, E: Display>(result: Result<T, E>) -> T {
175+ match result {
176+ Ok(value) => value,
177+ Err(e) => {
178+ println!("ERR {e}");
179+ std::process::exit(3)
180+ }
181+ }
182+}
183+
184+fn encode_job() {
185+ let env = |k: &str| std::env::var(k).expect("job variable");
186+ let num = |k: &str| env(k).parse::<u32>().expect("job number");
187+ let spec = spec_from_key(&env("CODEC"));
188+ let (w, h) = (num("W"), num("H"));
189+ let backend = backend_from_key(&env("BACKEND"));
190+ let value = num("VALUE");
191+ let mode = if env("MODE") == "cqp" {
192+ Mode::Cqp(value)
193+ } else {
194+ Mode::Cbr(value)
195+ };
196+ let frames = read_frames(Path::new(&env("SOURCE")), w, h);
197+ let mut config = EncoderConfig::new(spec.enc, w, h);
198+ config.framerate = (FPS, 1);
199+ config.gop_size = GOP;
200+ match mode {
201+ Mode::Cqp(qp) => config.rate_control = RateControlMode::ConstantQp { qp },
202+ Mode::Cbr(bps) => {
203+ config.bitrate = bps;
204+ config.rate_control = RateControlMode::ConstantBitrate;
205+ }
206+ }
207+ let mut encoder = or_exit(HwEncoder::open(config, Some(backend)));
208+ let mut aus = Vec::with_capacity(frames.len());
209+ let start = Instant::now();
210+ for (t, frame) in frames.iter().enumerate() {
211+ let coded = or_exit(encoder.encode(
212+ frame,
213+ FrameMetadata {
214+ timestamp: t as i64,
215+ force_keyframe: false,
216+ },
217+ ));
218+ aus.push(coded.data);
219+ }
220+ let ms = start.elapsed().as_secs_f64() * 1000.0 / frames.len() as f64;
221+ write_aus(Path::new(&env("OUT")), &aus);
222+ println!("ENC ms={ms:.3} backend={:?}", encoder.backend());
223+}
224+
225+fn decode_job() {
226+ let env = |k: &str| std::env::var(k).expect("job variable");
227+ let spec = spec_from_key(&env("CODEC"));
228+ let backend = backend_from_key(&env("BACKEND"));
229+ let aus = read_aus(Path::new(&env("AUS")));
230+ let mut frames = 0usize;
231+ let elapsed = match backend {
232+ Backend::Vk => {
233+ let mut decoder = or_exit(HwDecoder::open(spec.dec));
234+ if decoder.backend() != Backend::Vk {
235+ println!("ERR opened on {:?}", decoder.backend());
236+ std::process::exit(3)
237+ }
238+ let start = Instant::now();
239+ for (t, au) in aus.iter().enumerate() {
240+ or_exit(decoder.decode(au, t as i64));
241+ while or_exit(decoder.next_frame()).is_some() {
242+ frames += 1;
243+ }
244+ }
245+ or_exit(decoder.flush());
246+ while or_exit(decoder.next_frame()).is_some() {
247+ frames += 1;
248+ }
249+ start.elapsed()
250+ }
251+ Backend::Va => {
252+ let display = or_exit(ec_va::open());
253+ let mut decoder = or_exit(ec_hw::Decoder::new(&display, spec.dec));
254+ let start = Instant::now();
255+ for (t, au) in aus.iter().enumerate() {
256+ or_exit(decoder.decode(au, t as i64));
257+ while let Some(frame) = decoder.next_frame() {
258+ or_exit(frame.to_i420());
259+ frames += 1;
260+ }
261+ }
262+ or_exit(decoder.flush());
263+ while let Some(frame) = decoder.next_frame() {
264+ or_exit(frame.to_i420());
265+ frames += 1;
266+ }
267+ start.elapsed()
268+ }
269+ };
270+ if frames != FRAMES {
271+ println!("ERR decoded {frames} of {FRAMES} frames");
272+ std::process::exit(3)
273+ }
274+ println!("DEC ms={:.3}", elapsed.as_secs_f64() * 1000.0 / FRAMES as f64);
275+}
276+
277+fn run_job(me: &Path, envs: &[(&str, String)]) -> Result<String, String> {
278+ let output = Command::new(me)
279+ .envs(envs.iter().map(|(k, v)| (*k, v.as_str())))
280+ .output()
281+ .expect("run child job");
282+ let stdout = String::from_utf8_lossy(&output.stdout).into_owned();
283+ if output.status.success() {
284+ Ok(stdout)
285+ } else {
286+ let reason = stdout
287+ .lines()
288+ .rev()
289+ .find(|l| l.starts_with("ERR"))
290+ .unwrap_or("child failed")
291+ .to_string();
292+ Err(reason)
293+ }
294+}
295+
296+fn field(out: &str, key: &str) -> Option<f64> {
297+ out.lines()
298+ .find_map(|l| l.strip_prefix(key))
299+ .and_then(|rest| rest.split_whitespace().next())
300+ .and_then(|v| v.parse().ok())
301+}
302+
303+fn psnr_y(stream: &Path, format: &str, source: &Path, (w, h): (u32, u32)) -> Option<f64> {
304+ let rate = FPS.to_string();
305+ let size = format!("{w}x{h}");
306+ let out = Command::new("ffmpeg")
307+ .args(["-nostdin", "-v", "info", "-f", format, "-r", &rate, "-i"])
308+ .arg(stream)
309+ .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-s", &size, "-r", &rate, "-i"])
310+ .arg(source)
311+ .args(["-lavfi", "psnr", "-f", "null", "-"])
312+ .output()
313+ .ok()?;
314+ let text = String::from_utf8_lossy(&out.stderr);
315+ let at = text.rfind("PSNR y:")?;
316+ text[at + "PSNR y:".len()..]
317+ .split_whitespace()
318+ .next()?
319+ .parse::<f64>()
320+ .ok()
321+ .filter(|v| !v.is_nan())
322+}
323+
324+struct Row {
325+ bytes: usize,
326+ ms: f64,
327+ psnr: Option<f64>,
328+}
329+
330+fn encode_row(
331+ me: &Path,
332+ dir: &Path,
333+ tag: &str,
334+ raw: &Path,
335+ (w, h): (u32, u32),
336+ spec: Spec,
337+ mode: Mode,
338+ backend: Backend,
339+) -> Result<(Row, PathBuf), String> {
340+ let (mode_key, value) = mode.env();
341+ let aus_path = dir.join(format!("{tag}.aus"));
342+ let out = run_job(
343+ me,
344+ &[
345+ (JOB, "enc".to_string()),
346+ ("CODEC", spec.key.to_string()),
347+ ("W", w.to_string()),
348+ ("H", h.to_string()),
349+ ("BACKEND", backend_key(backend).to_string()),
350+ ("MODE", mode_key.to_string()),
351+ ("VALUE", value.to_string()),
352+ ("SOURCE", raw.display().to_string()),
353+ ("OUT", aus_path.display().to_string()),
354+ ],
355+ )?;
356+ let ms = field(&out, "ENC ms=").ok_or("no timing from encode job")?;
357+ let aus = read_aus(&aus_path);
358+ let stream = dir.join(format!("{tag}.{}", spec.format));
359+ fs::write(&stream, aus.concat()).expect("write stream");
360+ let row = Row {
361+ bytes: aus.iter().map(Vec::len).sum(),
362+ ms,
363+ psnr: psnr_y(&stream, spec.format, raw, (w, h)),
364+ };
365+ Ok((row, aus_path))
366+}
367+
368+fn decode_ms(me: &Path, aus: &Path, spec: Spec, backend: Backend) -> Result<f64, String> {
369+ let out = run_job(
370+ me,
371+ &[
372+ (JOB, "dec".to_string()),
373+ ("CODEC", spec.key.to_string()),
374+ ("BACKEND", backend_key(backend).to_string()),
375+ ("AUS", aus.display().to_string()),
376+ ],
377+ )?;
378+ field(&out, "DEC ms=").ok_or_else(|| "no timing from decode job".to_string())
379+}
380+
381+fn cell(v: Option<f64>, digits: usize) -> String {
382+ match v {
383+ Some(v) => format!("{v:.digits$}"),
384+ None => "n/a".to_string(),
385+ }
386+}
387+
388+fn main() {
389+ if let Ok(job) = std::env::var(JOB) {
390+ match job.as_str() {
391+ "enc" => encode_job(),
392+ _ => decode_job(),
393+ }
394+ return;
395+ }
396+ let dir = PathBuf::from(std::env::args().nth(1).expect("scratch dir argument"));
397+ let me = std::env::current_exe().expect("own path");
398+ let mut decode_inputs: Vec<(&'static str, (u32, u32), Spec, Backend, PathBuf)> = Vec::new();
399+
400+ for source in SOURCES {
401+ for (w, h) in SIZES {
402+ let raw = make_source(&dir, source, w, h);
403+ println!("== {source} {w}x{h}, {FRAMES} frames at {FPS} fps ==");
404+ println!(
405+ "{:<6} {:<8} {:<4} {:>9} {:>7} {:>8} {:>9}",
406+ "codec", "rc", "enc", "bytes", "kbps", "PSNR-Y", "ms/frame"
407+ );
408+ for spec in SPECS {
409+ for mode in modes(spec) {
410+ for backend in [Backend::Vk, Backend::Va] {
411+ let tag = format!(
412+ "{source}-{w}x{h}-{}-{}-{}",
413+ spec.key,
414+ mode.label().replace(' ', ""),
415+ backend_key(backend)
416+ );
417+ let label = mode.label();
418+ let name = format!("{backend:?}");
419+ match encode_row(&me, &dir, &tag, &raw, (w, h), spec, mode, backend) {
420+ Ok((row, aus)) => {
421+ let kbps = row.bytes as f64 * 8.0 * f64::from(FPS) / FRAMES as f64 / 1000.0;
422+ println!(
423+ "{:<6} {:<8} {:<4} {:>9} {:>7.0} {:>8} {:>9.2}",
424+ spec.name,
425+ label,
426+ name,
427+ row.bytes,
428+ kbps,
429+ cell(row.psnr, 2),
430+ row.ms
431+ );
432+ if matches!(mode, Mode::Cbr(b) if b == DECODE_BITRATE) {
433+ decode_inputs.push((source, (w, h), spec, backend, aus));
434+ }
435+ }
436+ Err(reason) => println!(
437+ "{:<6} {:<8} {:<4} n/a: {reason}",
438+ spec.name, label, name
439+ ),
440+ }
441+ }
442+ }
443+ }
444+ println!();
445+ }
446+ }
447+
448+ println!("== decode, CBR {}M streams, ms/frame ==", DECODE_BITRATE / 1_000_000);
449+ println!(
450+ "{:<6} {:<10} {:<9} {:<4} {:>10} {:>10}",
451+ "codec", "source", "res", "enc", "Vk dec", "VA dec"
452+ );
453+ for (source, (w, h), spec, enc_backend, aus) in &decode_inputs {
454+ let vk = decode_ms(&me, aus, *spec, Backend::Vk);
455+ let va = decode_ms(&me, aus, *spec, Backend::Va);
456+ println!(
457+ "{:<6} {:<10} {:<9} {:<4} {:>10} {:>10}",
458+ spec.name,
459+ source,
460+ format!("{w}x{h}"),
461+ format!("{enc_backend:?}"),
462+ cell(vk.ok(), 2),
463+ cell(va.ok(), 2)
464+ );
465+ }
466+}
crates/ec-hw/src/error.rsmodified+7 -1
@@ -87,7 +87,13 @@ impl From<ec_va::Error> for Error {
87 87
88 impl From<ec_vk::Error> for Error {88 impl From<ec_vk::Error> for Error {
89 fn from(e: ec_vk::Error) -> Error {89 fn from(e: ec_vk::Error) -> Error {
90- Error::Vk(e.to_string())90+ match e {
91+ ec_vk::Error::DeviceLost(call) => {
92+ crate::reset::report_gpu_reset();
93+ Error::hw_reset(format!("Vulkan device lost in {call}"))
94+ }
95+ other => Error::Vk(other.to_string()),
96+ }
91 }97 }
92 }98 }
93 99
crates/ec-hw/src/hw.rsmodified+51 -5
@@ -6,6 +6,8 @@ use std::os::fd::BorrowedFd;
6 #[cfg(target_os = "linux")]6 #[cfg(target_os = "linux")]
7 use ec_vk::DmaBuf;7 use ec_vk::DmaBuf;
8 8
9+use std::cell::RefCell;
10+
9 use crate::error::{Error, Result};11 use crate::error::{Error, Result};
10 use crate::picture::{Decoded, I420, RgbPicture};12 use crate::picture::{Decoded, I420, RgbPicture};
11 #[cfg(target_os = "linux")]13 #[cfg(target_os = "linux")]
@@ -59,11 +61,41 @@ pub struct Capability {
59 }61 }
60 62
61 thread_local! {63 thread_local! {
62- static GPU: Option<ec_vk::Gpu> = ec_vk::Gpu::open().ok();64+ static GPU: RefCell<Option<(u64, Option<ec_vk::Gpu>)>> = const { RefCell::new(None) };
63 }65 }
64 66
65 pub(crate) fn vk_gpu() -> Option<ec_vk::Gpu> {67 pub(crate) fn vk_gpu() -> Option<ec_vk::Gpu> {
66- GPU.with(|gpu| gpu.clone())68+ GPU.with_borrow_mut(|cached| {
69+ let epoch = crate::reset::gpu_reset_epoch();
70+ match cached {
71+ Some((born, gpu)) if *born == epoch => gpu.clone(),
72+ _ => {
73+ let gpu = ec_vk::Gpu::open().ok();
74+ *cached = Some((epoch, gpu.clone()));
75+ gpu
76+ }
77+ }
78+ })
79+}
80+
81+fn vk_session_alive(born_epoch: u64) -> Result<()> {
82+ if crate::reset::gpu_reset_epoch() == born_epoch {
83+ Ok(())
84+ } else {
85+ Err(Error::hw_reset(
86+ "the GPU was reset after this Vulkan session was created; its device is lost",
87+ ))
88+ }
89+}
90+
91+fn vk_grace() -> Result<()> {
92+ if crate::reset::gpu_recently_reset() {
93+ Err(Error::hw_reset(
94+ "the GPU was reset moments ago; new Vulkan sessions wait out the grace period",
95+ ))
96+ } else {
97+ Ok(())
98+ }
67 }99 }
68 100
69 /// Every codec, direction and backend this machine can use. Never fails.101 /// Every codec, direction and backend this machine can use. Never fails.
@@ -337,6 +369,7 @@ enum EncInner {
337 /// A hardware encoder on whichever backend opened.369 /// A hardware encoder on whichever backend opened.
338 pub struct HwEncoder {370 pub struct HwEncoder {
339 inner: EncInner,371 inner: EncInner,
372+ born_epoch: u64,
340 config: EncoderConfig,373 config: EncoderConfig,
341 #[cfg_attr(not(target_os = "linux"), allow(dead_code))]374 #[cfg_attr(not(target_os = "linux"), allow(dead_code))]
342 size: (usize, usize),375 size: (usize, usize),
@@ -351,11 +384,13 @@ impl HwEncoder {
351 };384 };
352 let mut reasons = Vec::new();385 let mut reasons = Vec::new();
353 for backend in order {386 for backend in order {
387+ let born_epoch = crate::reset::gpu_reset_epoch();
354 match open_backend(backend, config) {388 match open_backend(backend, config) {
355 Ok(inner) => {389 Ok(inner) => {
356 let size = (config.width as usize, config.height as usize);390 let size = (config.width as usize, config.height as usize);
357 return Ok(HwEncoder {391 return Ok(HwEncoder {
358 inner,392 inner,
393+ born_epoch,
359 config,394 config,
360 size,395 size,
361 });396 });
@@ -382,6 +417,7 @@ impl HwEncoder {
382 pub fn tune(&mut self, tunings: Tunings) -> Result<()> {417 pub fn tune(&mut self, tunings: Tunings) -> Result<()> {
383 match &mut self.inner {418 match &mut self.inner {
384 EncInner::Vk(enc) => {419 EncInner::Vk(enc) => {
420+ vk_session_alive(self.born_epoch)?;
385 let rate = match self.config.rate_control {421 let rate = match self.config.rate_control {
386 RateControlMode::ConstantQp { .. } => vk_rate(&self.config),422 RateControlMode::ConstantQp { .. } => vk_rate(&self.config),
387 _ => ec_vk::RateControl::Cbr {423 _ => ec_vk::RateControl::Cbr {
@@ -400,6 +436,7 @@ impl HwEncoder {
400 pub fn encode(&mut self, frame: &I420, meta: FrameMetadata) -> Result<CodedFrame> {436 pub fn encode(&mut self, frame: &I420, meta: FrameMetadata) -> Result<CodedFrame> {
401 match &mut self.inner {437 match &mut self.inner {
402 EncInner::Vk(enc) => {438 EncInner::Vk(enc) => {
439+ vk_session_alive(self.born_epoch)?;
403 let coded = enc.encode(frame, meta.force_keyframe)?;440 let coded = enc.encode(frame, meta.force_keyframe)?;
404 Ok(CodedFrame {441 Ok(CodedFrame {
405 data: coded.data,442 data: coded.data,
@@ -416,6 +453,7 @@ impl HwEncoder {
416 pub fn encode_rgb(&mut self, frame: &RgbFrame, meta: FrameMetadata) -> Result<CodedFrame> {453 pub fn encode_rgb(&mut self, frame: &RgbFrame, meta: FrameMetadata) -> Result<CodedFrame> {
417 match &mut self.inner {454 match &mut self.inner {
418 EncInner::Vk(enc) => {455 EncInner::Vk(enc) => {
456+ vk_session_alive(self.born_epoch)?;
419 let coded = enc.encode_rgb(frame, meta.force_keyframe)?;457 let coded = enc.encode_rgb(frame, meta.force_keyframe)?;
420 Ok(CodedFrame {458 Ok(CodedFrame {
421 data: coded.data,459 data: coded.data,
@@ -437,6 +475,7 @@ impl HwEncoder {
437 ) -> Result<CodedFrame> {475 ) -> Result<CodedFrame> {
438 match &mut self.inner {476 match &mut self.inner {
439 EncInner::Vk(enc) => {477 EncInner::Vk(enc) => {
478+ vk_session_alive(self.born_epoch)?;
440 let coded = enc.encode_dmabuf(frame, meta.force_keyframe)?;479 let coded = enc.encode_dmabuf(frame, meta.force_keyframe)?;
441 Ok(CodedFrame {480 Ok(CodedFrame {
442 data: coded.data,481 data: coded.data,
@@ -460,6 +499,7 @@ fn open_backend(backend: Backend, config: EncoderConfig) -> Result<EncInner> {
460 }499 }
461 500
462 fn open_vk(config: EncoderConfig) -> Result<VkEncoder> {501 fn open_vk(config: EncoderConfig) -> Result<VkEncoder> {
502+ vk_grace()?;
463 if config.bit_depth != 8 {503 if config.bit_depth != 8 {
464 return Err(Error::unsupported(504 return Err(Error::unsupported(
465 "10-bit Vulkan Video encode",505 "10-bit Vulkan Video encode",
@@ -599,6 +639,7 @@ enum Mode {
599 /// A hardware decoder on whichever backend opened.639 /// A hardware decoder on whichever backend opened.
600 pub struct HwDecoder {640 pub struct HwDecoder {
601 inner: DecInner,641 inner: DecInner,
642+ born_epoch: u64,
602 #[cfg_attr(not(target_os = "linux"), allow(dead_code))]643 #[cfg_attr(not(target_os = "linux"), allow(dead_code))]
603 codec: Codec,644 codec: Codec,
604 mode: Mode,645 mode: Mode,
@@ -623,16 +664,18 @@ impl HwDecoder {
623 Mode::Rgb(output) => Some(output),664 Mode::Rgb(output) => Some(output),
624 };665 };
625 let mut reasons = Vec::new();666 let mut reasons = Vec::new();
626- let vk = match codec {667+ let born_epoch = crate::reset::gpu_reset_epoch();
668+ let vk = vk_grace().and_then(|()| match codec {
627 Codec::H264 => VkH264Decoder::new(rgb).map(VkDecoder::H264),669 Codec::H264 => VkH264Decoder::new(rgb).map(VkDecoder::H264),
628 Codec::H265 => VkH265Decoder::new(rgb).map(VkDecoder::H265),670 Codec::H265 => VkH265Decoder::new(rgb).map(VkDecoder::H265),
629 Codec::Av1 => VkAv1Decoder::new(rgb).map(VkDecoder::Av1),671 Codec::Av1 => VkAv1Decoder::new(rgb).map(VkDecoder::Av1),
630 Codec::Vp9 => VkVp9Decoder::new(rgb).map(VkDecoder::Vp9),672 Codec::Vp9 => VkVp9Decoder::new(rgb).map(VkDecoder::Vp9),
631- };673+ });
632 match vk {674 match vk {
633 Ok(inner) => {675 Ok(inner) => {
634 return Ok(HwDecoder {676 return Ok(HwDecoder {
635 inner: DecInner::Vk(inner),677 inner: DecInner::Vk(inner),
678+ born_epoch,
636 codec,679 codec,
637 mode,680 mode,
638 replay: Some(Vec::new()),681 replay: Some(Vec::new()),
@@ -646,6 +689,7 @@ impl HwDecoder {
646 Ok(inner) => {689 Ok(inner) => {
647 return Ok(HwDecoder {690 return Ok(HwDecoder {
648 inner: DecInner::Va(inner),691 inner: DecInner::Va(inner),
692+ born_epoch,
649 codec,693 codec,
650 mode,694 mode,
651 replay: None,695 replay: None,
@@ -672,8 +716,9 @@ impl HwDecoder {
672 /// Feed one access unit. A stream Vulkan refuses (an unsupported profile) before its first716 /// Feed one access unit. A stream Vulkan refuses (an unsupported profile) before its first
673 /// picture comes out moves to VA-API on Linux, replaying what was fed so far.717 /// picture comes out moves to VA-API on Linux, replaying what was fed so far.
674 pub fn decode(&mut self, data: &[u8], timestamp: i64) -> Result<()> {718 pub fn decode(&mut self, data: &[u8], timestamp: i64) -> Result<()> {
719+ let born_epoch = self.born_epoch;
675 let result = match &mut self.inner {720 let result = match &mut self.inner {
676- DecInner::Vk(d) => d.decode(data, timestamp),721+ DecInner::Vk(d) => vk_session_alive(born_epoch).and_then(|()| d.decode(data, timestamp)),
677 #[cfg(target_os = "linux")]722 #[cfg(target_os = "linux")]
678 DecInner::Va(d) => d.decode(data, timestamp),723 DecInner::Va(d) => d.decode(data, timestamp),
679 };724 };
@@ -724,6 +769,7 @@ impl HwDecoder {
724 fn pull(&mut self) -> Result<Option<(i64, Decoded)>> {769 fn pull(&mut self) -> Result<Option<(i64, Decoded)>> {
725 match &mut self.inner {770 match &mut self.inner {
726 DecInner::Vk(d) => {771 DecInner::Vk(d) => {
772+ vk_session_alive(self.born_epoch)?;
727 let frame = d.next_frame();773 let frame = d.next_frame();
728 if frame.is_some() {774 if frame.is_some() {
729 self.replay = None;775 self.replay = None;
crates/ec-hw/tests/intra_rate.rsmodified+64 -49
@@ -24,10 +24,8 @@ use std::fs::File;
24 use std::os::unix::fs::FileExt;24 use std::os::unix::fs::FileExt;
25 use std::path::{Path, PathBuf};25 use std::path::{Path, PathBuf};
26 use std::process::Command;26 use std::process::Command;
27-use std::rc::Rc;
28 27
29-use ec_hw::{EncCodec, Encoder, EncoderConfig, FrameMetadata, I420, RateControlMode};28+use ec_hw::{Backend, EncCodec, EncoderConfig, FrameMetadata, HwEncoder, I420, RateControlMode};
30-use ec_va::Display;
31 29
32 const WIDTH: u32 = 1280;30 const WIDTH: u32 = 1280;
33 const HEIGHT: u32 = 720;31 const HEIGHT: u32 = 720;
@@ -41,20 +39,30 @@ const CHILD_CODEC: &str = "EC_INTRA_RATE_CODEC";
41 const CHILD_GOP: &str = "EC_INTRA_RATE_GOP";39 const CHILD_GOP: &str = "EC_INTRA_RATE_GOP";
42 const CHILD_BITRATE: &str = "EC_INTRA_RATE_BITRATE";40 const CHILD_BITRATE: &str = "EC_INTRA_RATE_BITRATE";
43 const CHILD_MODE: &str = "EC_INTRA_RATE_MODE";41 const CHILD_MODE: &str = "EC_INTRA_RATE_MODE";
42+const CHILD_BACKEND: &str = "EC_INTRA_RATE_BACKEND";
44 const CHILD_SOURCE: &str = "EC_INTRA_RATE_SOURCE";43 const CHILD_SOURCE: &str = "EC_INTRA_RATE_SOURCE";
45 const CHILD_OUT: &str = "EC_INTRA_RATE_OUT";44 const CHILD_OUT: &str = "EC_INTRA_RATE_OUT";
46 const DELIVERED_LINE: &str = "DELIVERED_BPS=";45 const DELIVERED_LINE: &str = "DELIVERED_BPS=";
47 46
48-fn display() -> Option<Rc<Display>> {47+fn backend_key(backend: Backend) -> &'static str {
49- match ec_va::open() {48+ match backend {
50- Ok(display) => Some(display),49+ Backend::Vk => "vk",
51- Err(e) => {50+ Backend::Va => "va",
52- eprintln!("skipped: no VA display ({e})");51+ }
53- None52+}
54- }53+
54+fn backend_from_key(key: &str) -> Backend {
55+ match key {
56+ "vk" => Backend::Vk,
57+ _ => Backend::Va,
55 }58 }
56 }59 }
57 60
61+fn opens(codec: EncCodec, backend: Backend) -> bool {
62+ let config = EncoderConfig::new(codec, WIDTH, HEIGHT);
63+ HwEncoder::open(config, Some(backend)).is_ok()
64+}
65+
58 fn scratch() -> PathBuf {66 fn scratch() -> PathBuf {
59 let dir = std::env::temp_dir().join("ec-hw-intra-rate");67 let dir = std::env::temp_dir().join("ec-hw-intra-rate");
60 std::fs::create_dir_all(&dir).expect("scratch dir");68 std::fs::create_dir_all(&dir).expect("scratch dir");
@@ -104,19 +112,19 @@ fn picture(file: &File, t: u32) -> I420 {
104 /// One encode of the clip with an IDR every `gop` pictures: the stream, and the112 /// One encode of the clip with an IDR every `gop` pictures: the stream, and the
105 /// bits per second it actually spent.113 /// bits per second it actually spent.
106 fn encode(114 fn encode(
115+ backend: Backend,
107 codec: EncCodec,116 codec: EncCodec,
108 gop: u32,117 gop: u32,
109 bitrate: u32,118 bitrate: u32,
110 rate_control: RateControlMode,119 rate_control: RateControlMode,
111 raw: &File,120 raw: &File,
112 ) -> (Vec<u8>, f64) {121 ) -> (Vec<u8>, f64) {
113- let display = display().expect("a VA display");
114 let mut config = EncoderConfig::new(codec, WIDTH, HEIGHT);122 let mut config = EncoderConfig::new(codec, WIDTH, HEIGHT);
115 config.framerate = (FPS, 1);123 config.framerate = (FPS, 1);
116 config.gop_size = gop;124 config.gop_size = gop;
117 config.bitrate = bitrate;125 config.bitrate = bitrate;
118 config.rate_control = rate_control;126 config.rate_control = rate_control;
119- let mut encoder = Encoder::new(&display, config).expect("encoder");127+ let mut encoder = HwEncoder::open(config, Some(backend)).expect("encoder");
120 let mut out = Vec::new();128 let mut out = Vec::new();
121 for t in 0..FRAMES {129 for t in 0..FRAMES {
122 let coded = encoder130 let coded = encoder
@@ -179,8 +187,9 @@ fn one_encode_in_its_own_process() {
179 },187 },
180 _ => RateControlMode::ConstantBitrate,188 _ => RateControlMode::ConstantBitrate,
181 };189 };
190+ let backend = backend_from_key(&std::env::var(CHILD_BACKEND).expect("backend"));
182 let raw = File::open(std::env::var(CHILD_SOURCE).expect("source")).expect("source clip");191 let raw = File::open(std::env::var(CHILD_SOURCE).expect("source")).expect("source clip");
183- let (stream, delivered) = encode(codec, gop, bitrate, rate_control, &raw);192+ let (stream, delivered) = encode(backend, codec, gop, bitrate, rate_control, &raw);
184 std::fs::write(std::env::var(CHILD_OUT).expect("out"), &stream).expect("write stream");193 std::fs::write(std::env::var(CHILD_OUT).expect("out"), &stream).expect("write stream");
185 println!("{DELIVERED_LINE}{delivered}");194 println!("{DELIVERED_LINE}{delivered}");
186 }195 }
@@ -188,6 +197,7 @@ fn one_encode_in_its_own_process() {
188 /// One encode in a child process of this test binary. Returns the stream's197 /// One encode in a child process of this test binary. Returns the stream's
189 /// delivered bits per second, written to `out`.198 /// delivered bits per second, written to `out`.
190 fn encode_in_its_own_process(199 fn encode_in_its_own_process(
200+ backend: Backend,
191 codec: EncCodec,201 codec: EncCodec,
192 gop: u32,202 gop: u32,
193 bitrate: u32,203 bitrate: u32,
@@ -207,6 +217,7 @@ fn encode_in_its_own_process(
207 .env(CHILD_GOP, gop.to_string())217 .env(CHILD_GOP, gop.to_string())
208 .env(CHILD_BITRATE, bitrate.to_string())218 .env(CHILD_BITRATE, bitrate.to_string())
209 .env(CHILD_MODE, if coarsest_qp { "coarsest" } else { "cbr" })219 .env(CHILD_MODE, if coarsest_qp { "coarsest" } else { "cbr" })
220+ .env(CHILD_BACKEND, backend_key(backend))
210 .env(CHILD_SOURCE, source)221 .env(CHILD_SOURCE, source)
211 .env(CHILD_OUT, out)222 .env(CHILD_OUT, out)
212 .output()223 .output()
@@ -252,9 +263,6 @@ fn psnr(coded: &Path, format: &str, source: &Path) -> Option<f64> {
252 263
253 #[test]264 #[test]
254 fn cbr_lands_within_five_percent_on_intra_only_and_gop_30() {265 fn cbr_lands_within_five_percent_on_intra_only_and_gop_30() {
255- if display().is_none() {
256- return;
257- }
258 let dir = scratch();266 let dir = scratch();
259 let Some(source) = testsrc2_raw(&dir) else {267 let Some(source) = testsrc2_raw(&dir) else {
260 eprintln!("skipped: ffmpeg cannot generate testsrc2");268 eprintln!("skipped: ffmpeg cannot generate testsrc2");
@@ -265,40 +273,47 @@ fn cbr_lands_within_five_percent_on_intra_only_and_gop_30() {
265 println!(273 println!(
266 "CBR, testsrc2 {WIDTH}x{HEIGHT} {FPS} fps, {FRAMES} pictures (floor = coarsest quantiser):"274 "CBR, testsrc2 {WIDTH}x{HEIGHT} {FPS} fps, {FRAMES} pictures (floor = coarsest quantiser):"
267 );275 );
268- for (codec, name, format) in [276+ for backend in [Backend::Va, Backend::Vk] {
269- (EncCodec::H264, "H.264", "h264"),277+ for (codec, name, format) in [
270- (EncCodec::H265, "HEVC", "hevc"),278+ (EncCodec::H264, "H.264", "h264"),
271- (EncCodec::Av1, "AV1", "obu"),279+ (EncCodec::H265, "HEVC", "hevc"),
272- ] {280+ (EncCodec::Av1, "AV1", "obu"),
273- for gop in GOPS {281+ ] {
274- // The smallest stream this codec makes for the clip at this GOP.282+ if !opens(codec, backend) {
275- let floor_path = dir.join(format!("{name}-gop{gop}-floor.{format}"));283+ println!(" {backend:?} {name}: skipped, the encoder does not open");
276- let floor = encode_in_its_own_process(codec, gop, 0, true, &source, &floor_path);284+ continue;
277- for bitrate in BITRATES {285+ }
278- let coded = dir.join(format!("{name}-gop{gop}-{bitrate}.{format}"));286+ for gop in GOPS {
279- let delivered =287+ let floor_path = dir.join(format!("{backend:?}-{name}-gop{gop}-floor.{format}"));
280- encode_in_its_own_process(codec, gop, bitrate, false, &source, &coded);288+ let floor =
281- let db = psnr(&coded, format, &source).unwrap_or(f64::NAN);289+ encode_in_its_own_process(backend, codec, gop, 0, true, &source, &floor_path);
282- let error = delivered / f64::from(bitrate) - 1.0;290+ for bitrate in BITRATES {
283- let at_floor =291+ let coded = dir.join(format!("{backend:?}-{name}-gop{gop}-{bitrate}.{format}"));
284- f64::from(bitrate) < floor && (delivered / floor - 1.0).abs() <= 0.05;292+ let delivered = encode_in_its_own_process(
285- println!(293+ backend, codec, gop, bitrate, false, &source, &coded,
286- " {name:<6} GOP {gop:>2} request {:>5} kbps -> {:>6.0} kbps ({:+6.1}%), floor {:>6.0} kbps, {db:.2} dB{}",294+ );
287- bitrate / 1000,295+ let db = psnr(&coded, format, &source).unwrap_or(f64::NAN);
288- delivered / 1000.0,296+ let error = delivered / f64::from(bitrate) - 1.0;
289- error * 100.0,297+ let at_floor =
290- floor / 1000.0,298+ f64::from(bitrate) < floor && (delivered / floor - 1.0).abs() <= 0.05;
291- if at_floor {299+ println!(
292- " (at the coarsest quantiser)"300+ " {backend:?} {name:<6} GOP {gop:>2} request {:>5} kbps -> {:>6.0} kbps ({:+6.1}%), floor {:>6.0} kbps, {db:.2} dB{}",
293- } else {301+ bitrate / 1000,
294- ""302+ delivered / 1000.0,
303+ error * 100.0,
304+ floor / 1000.0,
305+ if at_floor {
306+ " (at the coarsest quantiser)"
307+ } else {
308+ ""
309+ }
310+ );
311+ if error.abs() > 0.05 && !at_floor {
312+ failures.push(format!(
313+ "{backend:?} {name} GOP {gop} at {bitrate} bps: {:+.1}%",
314+ error * 100.0
315+ ));
295 }316 }
296- );
297- if error.abs() > 0.05 && !at_floor {
298- failures.push(format!(
299- "{name} GOP {gop} at {bitrate} bps: {:+.1}%",
300- error * 100.0
301- ));
302 }317 }
303 }318 }
304 }319 }
shims/vk-video-ffi/src/lib.rsmodified+8 -5
@@ -75,6 +75,8 @@ pub enum Error {
75 NoDevice,75 NoDevice,
76 /// A Vulkan call failed: VkResult code and call name.76 /// A Vulkan call failed: VkResult code and call name.
77 Vk(i32, &'static str),77 Vk(i32, &'static str),
78+ /// The device was lost (VK_ERROR_DEVICE_LOST): a GPU reset or a hung queue. Every object on it is dead.
79+ DeviceLost(&'static str),
78 /// The requested codec or direction is not supported.80 /// The requested codec or direction is not supported.
79 Unsupported(String),81 Unsupported(String),
80 /// The caller passed an invalid picture, buffer or sequence state.82 /// The caller passed an invalid picture, buffer or sequence state.
@@ -87,6 +89,7 @@ impl fmt::Display for Error {
87 Error::NoLoader(e) => write!(f, "no Vulkan loader: {e}"),89 Error::NoLoader(e) => write!(f, "no Vulkan loader: {e}"),
88 Error::NoDevice => write!(f, "no Vulkan Video device"),90 Error::NoDevice => write!(f, "no Vulkan Video device"),
89 Error::Vk(code, call) => write!(f, "{call} failed: VkResult {code}"),91 Error::Vk(code, call) => write!(f, "{call} failed: VkResult {code}"),
92+ Error::DeviceLost(call) => write!(f, "{call} failed: device lost"),
90 Error::Unsupported(what) => write!(f, "unsupported: {what}"),93 Error::Unsupported(what) => write!(f, "unsupported: {what}"),
91 Error::Invalid(what) => write!(f, "invalid: {what}"),94 Error::Invalid(what) => write!(f, "invalid: {what}"),
92 }95 }
@@ -177,7 +180,7 @@ fn queue_families(instance: &Instance, physical: vk::PhysicalDevice) -> Families
177 180
178 fn setup(instance: &Instance) -> Result<(vk::PhysicalDevice, Device, String, Families), Error> {181 fn setup(instance: &Instance) -> Result<(vk::PhysicalDevice, Device, String, Families), Error> {
179 let devices = unsafe { instance.enumerate_physical_devices() }182 let devices = unsafe { instance.enumerate_physical_devices() }
180- .map_err(|c| Error::Vk(c.as_raw(), "vkEnumeratePhysicalDevices"))?;183+ .map_err(|c| crate::session::vk_error(c, "vkEnumeratePhysicalDevices"))?;
181 let (physical, families) = devices184 let (physical, families) = devices
182 .into_iter()185 .into_iter()
183 .find_map(|pd| {186 .find_map(|pd| {
@@ -203,7 +206,7 @@ fn setup(instance: &Instance) -> Result<(vk::PhysicalDevice, Device, String, Fam
203 206
204 let available: Vec<vk::ExtensionName> =207 let available: Vec<vk::ExtensionName> =
205 unsafe { instance.enumerate_device_extension_properties(physical, None) }208 unsafe { instance.enumerate_device_extension_properties(physical, None) }
206- .map_err(|c| Error::Vk(c.as_raw(), "vkEnumerateDeviceExtensionProperties"))?209+ .map_err(|c| crate::session::vk_error(c, "vkEnumerateDeviceExtensionProperties"))?
207 .iter()210 .iter()
208 .map(|e| e.extension_name)211 .map(|e| e.extension_name)
209 .collect();212 .collect();
@@ -238,7 +241,7 @@ fn setup(instance: &Instance) -> Result<(vk::PhysicalDevice, Device, String, Fam
238 .enabled_extension_names(&names)241 .enabled_extension_names(&names)
239 .push_next(&mut features);242 .push_next(&mut features);
240 let device = unsafe { instance.create_device(physical, &info, None) }243 let device = unsafe { instance.create_device(physical, &info, None) }
241- .map_err(|c| Error::Vk(c.as_raw(), "vkCreateDevice"))?;244+ .map_err(|c| crate::session::vk_error(c, "vkCreateDevice"))?;
242 245
243 let name = unsafe { instance.get_physical_device_properties(physical) }246 let name = unsafe { instance.get_physical_device_properties(physical) }
244 .device_name247 .device_name
@@ -261,7 +264,7 @@ impl Gpu {
261 let app = vk::ApplicationInfo::builder().api_version(vk::make_version(1, 3, 0));264 let app = vk::ApplicationInfo::builder().api_version(vk::make_version(1, 3, 0));
262 let info = vk::InstanceCreateInfo::builder().application_info(&app);265 let info = vk::InstanceCreateInfo::builder().application_info(&app);
263 let instance = unsafe { entry.create_instance(&info, None) }266 let instance = unsafe { entry.create_instance(&info, None) }
264- .map_err(|c| Error::Vk(c.as_raw(), "vkCreateInstance"))?;267+ .map_err(|c| crate::session::vk_error(c, "vkCreateInstance"))?;
265 match setup(&instance) {268 match setup(&instance) {
266 Ok((physical, device, name, families)) => Ok(Gpu {269 Ok((physical, device, name, families)) => Ok(Gpu {
267 inner: Arc::new(Inner {270 inner: Arc::new(Inner {
@@ -488,7 +491,7 @@ impl Gpu {
488 &mut caps,491 &mut caps,
489 )492 )
490 }493 }
491- .map_err(|c| Error::Vk(c.as_raw(), "vkGetPhysicalDeviceVideoCapabilitiesKHR"))?;494+ .map_err(|c| crate::session::vk_error(c, "vkGetPhysicalDeviceVideoCapabilitiesKHR"))?;
492 Ok(CodecCaps {495 Ok(CodecCaps {
493 codec,496 codec,
494 direction,497 direction,
shims/vk-video-ffi/src/rgb_convert.rsmodified+1 -1
@@ -194,7 +194,7 @@ impl RgbConverter {
194 };194 };
195 unsafe { d.destroy_shader_module(module, None) };195 unsafe { d.destroy_shader_module(module, None) };
196 let pipeline = pipelines196 let pipeline = pipelines
197- .map_err(|c| Error::Vk(c.as_raw(), "vkCreateComputePipelines"))?197+ .map_err(|c| crate::session::vk_error(c, "vkCreateComputePipelines"))?
198 .0[0];198 .0[0];
199 199
200 let sizes = [vk::DescriptorPoolSize {200 let sizes = [vk::DescriptorPoolSize {
shims/vk-video-ffi/src/rgb_decode.rsmodified+1 -1
@@ -79,7 +79,7 @@ impl RgbPass {
79 };79 };
80 unsafe { d.destroy_shader_module(module, None) };80 unsafe { d.destroy_shader_module(module, None) };
81 let pipeline = pipelines81 let pipeline = pipelines
82- .map_err(|c| Error::Vk(c.as_raw(), "vkCreateComputePipelines"))?82+ .map_err(|c| crate::session::vk_error(c, "vkCreateComputePipelines"))?
83 .0[0];83 .0[0];
84 84
85 let sizes = [vk::DescriptorPoolSize {85 let sizes = [vk::DescriptorPoolSize {
shims/vk-video-ffi/src/session.rsmodified+9 -1
@@ -22,8 +22,16 @@ pub(crate) const INITIAL_VIRTUAL_BUFFER_MS: u32 = 12;
22 22
23 pub(crate) type Stage = (vk::ImageLayout, vk::PipelineStageFlags2, vk::AccessFlags2);23 pub(crate) type Stage = (vk::ImageLayout, vk::PipelineStageFlags2, vk::AccessFlags2);
24 24
25+pub(crate) fn vk_error(code: vk::ErrorCode, call: &'static str) -> Error {
26+ if code == vk::ErrorCode::DEVICE_LOST {
27+ Error::DeviceLost(call)
28+ } else {
29+ Error::Vk(code.as_raw(), call)
30+ }
31+}
32+
25 pub(crate) fn vk<T>(result: vulkanalia::VkResult<T>, call: &'static str) -> Result<T, Error> {33 pub(crate) fn vk<T>(result: vulkanalia::VkResult<T>, call: &'static str) -> Result<T, Error> {
26- result.map_err(|c| Error::Vk(c.as_raw(), call))34+ result.map_err(|c| vk_error(c, call))
27 }35 }
28 36
29 pub(crate) fn zeroed<T>() -> T {37 pub(crate) fn zeroed<T>() -> T {