craft-gpu-yuv: both provider modes take the same output sizes

YuvProvider::run now holds each output side to cpu::MAX_SIDE (16384)
with or without a device. Before, a context whose largest texture side
was above 16384 let a device run a job that the CPU mode refused with
TooLarge after reading the input.
This commit is contained in:
dotCooCoo committed 2026-11-23 23:58:44 -08:00
1 parent dfeb20ddcf
commit b67fab9d1b
3 files changed
+18 -2

No files matched your search

+2 -1
View File
@@ -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
+3 -1
View File
@@ -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 }));
}
+13
View File
@@ -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());