diff --git a/crates/gpu-yuv/README.md b/crates/gpu-yuv/README.md index cae588d0e6..9a39ce0ff3 100644 --- a/crates/gpu-yuv/README.md +++ b/crates/gpu-yuv/README.md @@ -48,7 +48,8 @@ are decimal digits. The provider checks the job against the context's `DeviceCaps` on every context, the null one included: each source and output side must be at most `max_texture_dimension_2d`, and the read-back layout with its padded rows (`FrameLayout::buffer_size`) and the RGBA8 input at most -`max_buffer_size` bytes. It checks the input's length before reading it. A +`max_buffer_size` bytes. Each output side must also be at most `cpu::MAX_SIDE` (16384), with or +without a device. It checks the input's length before reading it. A malformed, missing, repeated or unknown parameter, a wrong input count or length, and a size the caps or the conversion do not allow are `GpuFault::InvalidJob`. With a device, the provider also checks the device's own limits, and an error the device reports during the job is diff --git a/crates/gpu-yuv/src/job.rs b/crates/gpu-yuv/src/job.rs index cbbff522b6..4f98dccca8 100644 --- a/crates/gpu-yuv/src/job.rs +++ b/crates/gpu-yuv/src/job.rs @@ -206,8 +206,10 @@ impl GpuProvider for YuvProvider { let YuvJob { conversion, src_width, src_height, width, height } = spec; let layout = FrameLayout::new(conversion.format, width, height).map_err(fault)?; let caps = ctx.caps(); + // An output side is also held to `cpu::MAX_SIDE`, so that both provider modes take the + // same jobs. let limit = caps.max_texture_dimension_2d; - for (w, h) in [(src_width, src_height), (width, height)] { + for (w, h, limit) in [(src_width, src_height, limit), (width, height, limit.min(cpu::MAX_SIDE))] { if w > limit || h > limit { return Err(fault(Error::TooLarge { width: w, height: h, limit })); } diff --git a/crates/gpu-yuv/src/job_tests.rs b/crates/gpu-yuv/src/job_tests.rs index 32fa92b47b..c1a723da4b 100644 --- a/crates/gpu-yuv/src/job_tests.rs +++ b/crates/gpu-yuv/src/job_tests.rs @@ -186,6 +186,19 @@ fn jobs_past_the_context_caps_are_refused() { assert!(dispatch(&r, &mut ctx, &YuvJob::new(c, 64, 4, 64, 42).job(small)).is_ok()); } +#[test] +fn an_output_side_past_the_cpu_limit_is_refused_before_the_input_is_read() { + let r = registry(YuvProvider::new()); + let side = cpu::MAX_SIDE + 2; + let caps = DeviceCaps { max_texture_dimension_2d: side, ..DeviceCaps::default() }; + let mut ctx = Capped::new(caps); + let c = Conversion::new(Format::Nv12, Matrix::Bt709, Range::Limited); + let input = ctx.upload_buffer("input", &tests::noise(2, 2)).unwrap(); + let refused = invalid(r.dispatch(&mut ctx, &YuvJob::new(c, 2, 2, side, 2).job(input))); + assert!(refused.contains(&format!("{side}×2 is larger than the largest texture side, {}", cpu::MAX_SIDE)), "{refused}"); + assert_eq!(ctx.reads, 0, "the refused input is not read"); +} + #[test] fn an_input_past_the_buffer_limit_is_refused_before_it_is_read() { let r = registry(YuvProvider::new());