fix(camera-raw): Shadows and Highlights on a 2 px proxy develop on the CPU

per_pixel sent Shadows and Highlights to the GPU on frames 2 pixels on
the short side, whose pyramid has one level. The pass refused them, and
CameraRawGpu::develop took that as a GPU failure, so the dialog stayed
on the CPU for every later preview. A layer about 450 times wider than
tall has such a proxy. per_pixel now returns None for these frames, so
the CPU develops them and the GPU stays on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
fjamespriceandClaude Opus 5.5 committed 2026-11-09 02:41:55 -05:00
1 parent a60090fff5
commit e13e8e8afd
3 files changed
+32 -6

No files matched your search

+6 -4
View File
@@ -230,16 +230,18 @@ pub fn white_black_points(px: &[[f32; 4]], w: usize, h: usize, p: &CameraRaw) ->
/// Develop's stages for settings whose only spatial stage is Shadows and Highlights, on a
/// `w × h` image; `points` are the image's [`white_black_points`]. `None` when `p` needs another
/// spatial stage or Calibration (these stages don't run it), Shadows or Highlights on a frame
/// wider than the filter's working copy (the develop then filters a reduced copy), or Whites or
/// Blacks without Shadows and Highlights and without `points`. The points themselves leave
/// Calibration out, so a caller may cache them across Calibration changes.
/// wider than the filter's working copy (the develop then filters a reduced copy) or only 2
/// pixels on its short side, or Whites or Blacks without Shadows and Highlights and without
/// `points`. The points themselves leave Calibration out, so a caller may cache them across
/// Calibration changes.
pub fn per_pixel(p: &CameraRaw, w: usize, h: usize, float: bool, points: Option<(f32, f32)>) -> Option<PerPixel> {
if p.spatial_beyond_local_tone() || !p.calibration_neutral() {
return None;
}
// The develop leaves frames under 2 pixels on a side alone.
let local_tone = if w >= 2 && h >= 2 { LocalTone::new(p.shadows, p.highlights) } else { None };
if local_tone.is_some() && w.max(h) > WORK_SIDE {
// At 2 pixels on the short side the GPU pass's pyramid has one level, so the CPU develops it.
if local_tone.is_some() && (w.max(h) > WORK_SIDE || w.min(h) <= 2) {
return None;
}
let identity = p.is_identity();
+8 -2
View File
@@ -346,6 +346,10 @@ fn identity_leaves_pixels_alone_and_spatial_settings_have_no_pass() {
assert!(toned.local_tone.is_some() && toned.whites_blacks.is_none() && toned.measure_whites_blacks == Some([10.0, 0.0]));
// Wider than the filter's working copy, the develop filters a reduced copy: the CPU's.
assert!(per_pixel(&CameraRaw { shadows: 20.0, ..Default::default() }, 1601, 32, false, None).is_none());
// At 2 pixels on the short side the pass's pyramid has one level: the CPU's too.
for (w, h) in [(2, 2), (40, 2), (2, 40)] {
assert!(per_pixel(&CameraRaw { highlights: -20.0, ..Default::default() }, w, h, false, None).is_none(), "{w}×{h}");
}
}
#[test]
@@ -404,9 +408,11 @@ fn shadows_and_highlights() {
fn shadows_and_highlights_on_tiny_odd_and_flat_frames() {
let Some(mut g) = gpu() else { return };
let p = CameraRaw { shadows: 60.0, highlights: -40.0, whites: 20.0, ..Default::default() };
// A frame 2 pixels on a side has a one-level pyramid: the passes refuse it (the CPU develops it).
// A frame 2 pixels on a side has a one-level pyramid: `per_pixel` sends it to the CPU, and
// the pass still refuses stages built for it elsewhere.
for (w, h) in [(2, 2), (40, 2)] {
let stages = per_pixel(&p, w, h, false, None).unwrap();
assert!(per_pixel(&p, w, h, false, None).is_none(), "{w}×{h}");
let stages = per_pixel(&p, 3, 3, false, None).unwrap();
assert!(g.dev.develop(&g.device, &g.queue, None, &image(w, h, Depth::Eight), None, [w as u32, h as u32], &stages).is_err());
}
for size in [(3, 3), (5, 3), (37, 23), (300, 7)] {
@@ -293,6 +293,24 @@ mod tests {
assert_eq!((backend, shown == cpu), ("cpu", true), "default settings: the CPU returns them unchanged");
}
#[test]
fn shadows_on_a_two_pixel_proxy_develop_on_the_cpu_and_keep_the_gpu() {
let _gpu = photocraft_testkit::gpu_lock();
let Some((mut app, ctx)) = gpu_app(8) else { return };
force_pass(&app);
crate::camera_raw_ui::open(&mut app, &ctx).unwrap();
app.gpu.as_ref().expect("GPU canvas").wait_camera_raw_pass();
let Some(gpu) = app.camera_raw.as_ref().and_then(|d| d.gpu.as_ref()) else {
eprintln!("skipping: the device can't run the Camera Raw pass");
return;
};
// A layer about 450 times wider than tall has a 2 px tall proxy: its pyramid has one level.
let thin = vec![[0.4, 0.3, 0.2, 1.0]; 40 * 2];
assert!(gpu.develop(&thin, None, 40, 2, &CameraRaw { shadows: 50.0, ..Default::default() }, false).is_none());
let px = vec![[0.4, 0.3, 0.2, 1.0]; 64 * 48];
assert!(gpu.develop(&px, None, 64, 48, &CameraRaw { exposure: 0.5, ..Default::default() }, false).is_some(), "the GPU develop stays on");
}
#[test]
fn rendering_mode_cpu_keeps_the_cpu_develop() {
let _gpu = photocraft_testkit::gpu_lock();