234 Commits

Author SHA1 Message Date
skylar taylor-barrick e3e76fd0f0 Wait for the GPU warm-up before a test or headless process ends (#620) (#4697)
* LR-BEHAV-GPU: no GPU warm-up is still loading the driver when a test or headless process ends (issue #620)

The first frame starts the GPU device warm-up on a thread of its own. A process
that ended a few milliseconds later, as every test does under nextest, could
exit while that thread was inside the Vulkan loader's dlopen of the driver,
running libLLVM's initializers: a SIGSEGV after the test had passed, or a hang.
Only the window's exit (LightcraftApp::shutdown) waited for GPU work.

warm_up now counts as in flight from the moment it is called, before its thread
exists, and wait_warm_up waits for it. Dropping a LightcraftApp waits for it,
bounded, unless shutdown already ran.

* LR-BEHAV-GPU: warm_up counts as in flight before it marks itself started (issue #620)

A second warm_up call racing the first could find it marked started and return
before the first had entered the gate, so a host dropping its app right after
that second call saw no warm-up in flight. The gate is now entered first, a
call that starts nothing drops its entry, and a closed gate starts nothing.

* LR-BEHAV-GPU: the app waits for the GPU warm-up when dropped on native builds only (issue #620)

The web build has no warm-up thread (warm_up and wait_warm_up do nothing there),
and the web host replaces the app's UI state by moving it out of the app, which
a Drop impl forbids (E0509 in the wasm check).

* LR-BEHAV-GPU: a deterministic test for the app's warm-up wait on drop (issue #620)

Fred's review of #4697: the first regression test could pass without
exercising the wait — ready() || !enabled() also holds when the warm-up
finished or never started, and no pending warm-up was ever established.

The gpu crate exposes doc-hidden test support, hold_warm_up_for_test(),
entering the same gate the real warm_up enters: a substitute warm-up the
caller holds. The test proves it is in flight (wait_warm_up(ZERO) is
false), builds an app that never ran a frame on another thread (the app
is not Send — its host-service callbacks are not — so it is built there),
and verifies with channel synchronization that dropping the app does not
return while the hold is kept, and returns once it is released. Without
the wait in Drop for LightcraftApp it fails at that assertion; with it,
it passes. No GPU, no device, no timing beyond a one-second observation
window whose proof is the release.

---------

Co-authored-by: skylartaylor <skylartaylor@users.noreply.github.com>
2026-12-02 08:34:26 -06:00
skylar taylor-barrick e944599ef4 Share one GPU device in the thumbnail tests (#4992)
* Share one GPU device in the thumbnail tests

gpu_drawn_fixture created a new wgpu instance, adapter and device for every
test. Its vkEnumeratePhysicalDevices unloads drivers that expose no device,
while another test thread's render calls vkSetDebugUtilsObjectNameEXT on the
process-wide device; Vulkan loaders before 1.4.345 then walk freed loader
state and crash with SIGSEGV (KhronosGroup/Vulkan-Loader#1863). The fixture
now reuses the render device (gpu::shared_device), or one process-wide device
that is never dropped.

render::thumbnail_tests looped 200 times (2 test threads): 31/200 SIGSEGV
before, 0/200 after.

* Keep the thumbnail tests' fallback device from racing the render device

gpu::shared_device returned None while the render device could still be
created later (GPU rendering turned off by another test through app.gpu, the
window's device pending), and gpu_drawn_fixture then created a Vulkan instance
of its own while another thread's render could create and use the render
device: the Vulkan-Loader#1863 race again. shared_device now creates the render
device whatever the preference, and waits while the window's device is being
adopted, so None means no render device can exist in this process any more
(switched off by the environment, creation failed, or the process is ending).
The fixture creates its own device only when the environment switches the GPU
off or creating the device failed: once the process is ending it skips the
test rather than create a device during teardown. The wait for the window's
device has a 60 s deadline and then panics, since returning None would let the
fixture race the window's device.

shared_device overrides the switch that keeps the GPU off (also after a launch
that crashed creating the device, #136), so the app must not have it: it now
exists only in the gpu crate's tests and with a new test-support feature, off
by default, which only dev-dependencies turn on (ui-egui's, and the gpu crate's
own for tests/shared_device.rs). The app's and the workspace's normal builds
don't have it.

The fixture's texture work runs inside error scopes, so an error in it fails
the test instead of stopping GPU rendering for every test in the process.

tests/shared_device.rs: with GPU rendering off and the window's device pending,
shared_device waits for the adoption and settles the render device.
render::thumbnail_tests looped 100 times (2 test threads): 100/100 passed;
with LIGHTCRAFT_GPU=0 (the fixture's own device) 50/50 passed.
2026-12-02 08:34:06 -06:00
FredApps dfacce6ad3 Merge pull request #5007 from wanikhawar/perf/gpu-v14-heal-spot-boxes
GPU render: V14 heal spots read back only what each spot reads (#4960)
2026-12-02 12:40:29 +01:00
FredApps bc4c7e36d3 Merge pull request #4999 from wanikhawar/gpu/readback-staging-pool-4958
GPU: readbacks reuse staging buffers and wait only for their own submission (#4958)
2026-12-02 12:39:57 +01:00
FredApps 8bae0315c7 gpu: readback pool test counts only reusable staging buffers and holds the device test lock (#4958) 2026-12-02 10:12:39 +01:00
Khawar Zamman Wani 395402ead3 GPU render: V14 heal spots read back only what each spot reads (#4960)
Under process V14 the GPU renderer read the whole image back, ran the
spots on the CPU and uploaded the whole image again: about 120 ms of
transfer on a 24 MP export, even for one spot. Each spot now reads back
only the rectangle it reads (its box and its source patch,
`spots::spot_reads`), is healed on the CPU by the same code as the CPU
renderer (`spots::apply_spot`, split out of `spots::apply`), and only
its box is written back. The V13 path is unchanged.
2026-12-02 13:16:05 +05:30
FredApps 41e6341101 Merge main and #4047 into brush-stroke-feather; the stroke feather becomes process V16
Main gave V10 to the checked Bradford white balance (#4599) and 13 and 14 to the
Shadows calibration and the pinned heal; #4047 (Flow per radius travelled) is V15.
So this PR's stroke feather moves from V10 to the next free number, V16 = V15 plus
feather, as asked in the review comment on #4517.

- includes #4047's head (898de527) so the stack lands in order: V15 Flow, then V16 feather
- Process::V16 is LATEST and appended to Process::ALL; masks::stroke_feather,
  the GPU brush_aux word and brush_live switch on V16, not V10
- V1 to V15 render as before (a_saved_process_keeps_its_brush_look)
- docs/process-versions.md, parity checklist and whats-new (Unreleased) updated

Co-authored-by: Dimitrij Denissenko <dimitrij.denissenko@blacksquaremedia.com>
2026-12-02 11:51:23 +07:00
Khawar Zamman Wani c5bd44a1f7 GPU readback: pool staging buffers and wait only for this render's submission (#4958)
finish_and_read took a fresh MAP_READ staging buffer for every readback
(~96 MB for a 24 MP export) and waited for everything on the queue.
Staging buffers now share the free pool with storage buffers, matched on
usage so neither is handed out as the other, and are returned after a
clean copy-out (dropped after any failure). Gpu::submit returns the
SubmissionIndex and the readback waits only on it; the 60 s timeout,
the 10 s callback grace period and the lost-device handling are kept.
2026-12-02 08:47:58 +05:30
Dimitrij Denissenko 898de527b9 Merge upstream/main into fix/brush-flow-per-radius
Main still ends at process V14, so Flow per radius stays V15. Frame keeps
both brush_flow_per_radius and main's new downscale filter.
2026-11-28 15:27:45 +00:00
FredApps 42f676e4a5 Merge pull request #4032 from Bruno-Alumn/fix/window-surface-error-4029
GPU: the window's surface failing to configure no longer sends rendering to the CPU (#4029)
2026-11-27 23:21:45 +01:00
Bruno-Alumn ce5ce3745b GPU: only the window surface's wait-idle timeout leaves the renderer on 2026-11-27 16:53:57 +01:00
FredApps 4ce839b216 Merge pull request #2988 from radialmonster/fix-2970-export-sharpness
Export: Lanczos-3 downscale and a Gaussian luma unsharp mask for crisper exports
2026-11-26 16:15:27 +01:00
FredApps fac6b0a0b9 Merge pull request #4811 from FredApps/fredapps/sam3-dx12-eight-keys
SAM 3: reduce DX12 attention pipeline startup time
2026-11-26 16:10:59 +01:00
FredApps 6937d937f9 Merge main (4edf1ee286) into fix-2970-export-sharpness
Clean merge of main; engine clippy (all targets, -D warnings) passes locally.
2026-11-26 21:21:19 +07:00
FredApps d0a13f3587 Merge remote-tracking branch 'origin/main' into fredapps/sam3-dx12-eight-keys 2026-11-26 21:13:05 +07:00
FredApps 760a81fbb5 Merge main (3c6a9f2c47) into fix/issue-2438-feature-request-enhance-super-resolution
Full re-review after the branch rewrite (Add operator in the ONNX reader, net validation, CPU and reference runners; GPU planner refuses it as unsupported). Clean merge.
2026-11-26 21:05:47 +07:00
FredApps fe0e605fbc Merge branch 'sam3-gpu-4-detr' (with main merged) into sam3-gpu-5-mask-decoder
# Conflicts:
#	docs/ai-masks.md
2026-11-26 19:20:05 +07:00
FredApps cf2ffdd071 Merge branch 'sam3-gpu-3-necks' (with main merged) into sam3-gpu-4-detr 2026-11-26 19:19:50 +07:00
FredApps b8f1a55da6 Merge branch 'sam3-gpu-2-backbone' (with main merged) into sam3-gpu-3-necks 2026-11-26 19:19:50 +07:00
FredApps 3649cafdc6 Merge branch 'sam3-gpu-1-plumbing' (with main merged) into sam3-gpu-2-backbone 2026-11-26 19:19:30 +07:00
FredApps 60950965d6 Merge branch 'main' into sam3-gpu-1-plumbing
# Conflicts:
#	crates/segment/src/cpu.rs
#	crates/segment/src/detector.rs
#	crates/ui-egui/locales/cs.json
#	crates/ui-egui/locales/de.json
#	crates/ui-egui/locales/es.json
#	crates/ui-egui/locales/fi.json
#	crates/ui-egui/locales/fr.json
#	crates/ui-egui/locales/id.json
#	crates/ui-egui/locales/it.json
#	crates/ui-egui/locales/ja.json
#	crates/ui-egui/locales/pl.json
#	crates/ui-egui/locales/pt-br.json
#	crates/ui-egui/locales/ru.json
#	crates/ui-egui/locales/sv.json
#	crates/ui-egui/locales/uk.json
#	crates/ui-egui/locales/vi.json
#	crates/ui-egui/locales/zh-hans.json
#	crates/ui-egui/locales/zh-hant.json
2026-11-26 18:36:23 +07:00
Dimitrij Denissenko 30f80e0167 Merge upstream/main into fix/brush-flow-per-radius; Flow becomes process V15
Main shipped V13 (#3923) and V14 (#4069) after leaving 12 for this pull
request. A V12 Flow would now also change saved V13 and V14 photos, so it
becomes V15 = V14 plus Flow per brush radius travelled, the latest; V1 to
V14 keep the flow per dab. 11 and 12 name no process (render as V10).
2026-11-24 18:10:40 +00:00
Hoang Pham dc938d951b Merge main into heal/pinned-fill; the pinned heal is process V14
Main's latest is V13 (#523). The heal moves to V14 = V13 plus the pinned heal, so saved V13 spots keep the averaged heal; 9, 11 and 12 name no process (12 stays claimed by #4047).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 10:37:42 +07:00
Dimitrij Denissenko 70f3f6a49d Merge upstream/main into fix/brush-flow-per-radius; Flow becomes provisional process V12
Main now has V10 (checked Bradford white balance) and reserves 9 for #4069;
11 and 13 are claimed by open pull requests. Flow per brush radius
travelled moves to V12, marked provisional; earlier processes keep the flow
per dab and the Flow tests compare against V10. Main's two V10 white-balance
tests now set V10 explicitly instead of taking the default, which moves on.
2026-11-23 10:07:54 +00:00
Hoang Pham dc198f1810 Merge main into heal/pinned-fill; the pinned heal is process V11
main writes process V10 (#4599) and renders a saved 9 as V8. The pinned
heal becomes V11, after the latest writable process: HealMethod::of picks
it from V11, so saved V8, 9 and V10 spots render as they did on main. The
number 9 stays unused (main's docs no longer call it reserved for this PR).

saved_spots_before_v11_render_as_they_did pins Heal, Remove and Clone
pixels that main rendered for saved 8, 9 and 10, and checks V11 differs;
spots_match (GPU) runs on V10 and V11. main's two V10 white-balance tests
now ask for V10 instead of the default, which is V11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 12:26:10 +07:00
tecari0 115bace396 LR-MASK-BRUSH: V10 review fixes (no-Flow dabs, stroke bounds, Auto Mask)
- A dab with no Flow (at pen pressure 0) no longer sets the stroke's
  edge: it could make a light pen stroke stronger.
- The edge plane covers only the stroke's bounds and is combined in place,
  instead of a full-frame plane per stroke (about 92 MiB on 24 MP).
- Auto Mask strokes keep V9's accumulation: their edge follows the
  photo's, not the feather, and V10's build-up made their colour
  weighting count for far dabs too (a rejected dab added Flow, and a
  window render drifted from the whole frame by up to 10 LSB).
- whats-new and the LR-MASK-BRUSH row say the 90 % to 50 % example is at
  Flow 100, and that Auto Mask strokes are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 18:44:56 -08:00
eliets2 a4aaaa3383 Repair review branch integration 2026-11-18 20:22:51 +02:00
Lamsoda1123 07223327e0 SAM 3: reduce DX12 attention pipeline startup time 2026-11-18 20:58:49 +08:00
tecari0 368376552c LR-MASK-BRUSH: a brush stroke is feathered as one dab is (process V10)
A stroke accumulated every dab's falloff times its flow, and its dabs
lie r/4 apart, so their soft edges piled up into a nearly hard one: at
Feather 100 and Flow 100, halfway out from a straight stroke's centre
line was 0.90 covered, where one dab covers 0.50.

Process V10 keeps a stroke's Flow build-up (each dab that reaches a pixel
adds its flow, masks::feather_dab) apart from its edge (the highest
falloff of those dabs) and covers their product up to Density
(masks::stroke_coverage). At Flow 100 a stroke's edge then falls off over
the feather exactly as one dab's; below it the centre builds up by Flow
per radius travelled (V9) whatever the feather.

CPU, GPU (a 13th stroke-record word in the shape kernel) and the live
stroke share the helpers. V1 to V9 render as before; Feather 0 brushes
render as on V9. Stacked on #4047 (V9).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 04:34:57 -08:00
helgehelge123 434fc50d43 Merge branch 'sam3-gpu-4-detr' into sam3-gpu-5-mask-decoder
# Conflicts:
#	docs/ai-masks.md
#	docs/target-app-parity.md
2026-11-16 00:19:05 +01:00
helgehelge123 f3ed3c4846 Merge branch 'sam3-gpu-3-necks' into sam3-gpu-4-detr 2026-11-16 00:07:44 +01:00
helgehelge123 c17384fc74 Merge branch 'sam3-gpu-2-backbone' into sam3-gpu-3-necks 2026-11-16 00:01:14 +01:00
helgehelge123 d0c17759d7 Merge branch 'sam3-gpu-1-plumbing' into sam3-gpu-2-backbone 2026-11-15 23:41:26 +01:00
helgehelge123 30c6b4f87a Merge remote-tracking branch 'origin/main' into sam3-gpu-1-plumbing
# Conflicts:
#	crates/segment/src/lib.rs
2026-11-15 23:00:01 +01:00
Dimitrij Denissenko 66dd3343aa Merge upstream/main into fix/brush-flow-per-radius; Flow becomes process V9
Main took V8 for the Highlights/Shadows base (#3460), so brush Flow per
radius travelled is V9; V1 to V8 keep the flow per dab. The Lens Blur
brush that main added paints its live stroke with the same rule.
2026-11-11 21:41:07 +00:00
Hoang Pham 195cc32f71 LR-REM-HEAL: the pinned heal is process V9; doc comments for the functions the PR touches
main's V8 is the Highlights/Shadows base that keeps the gaps in dark
lettering (#3460). Merging main into this branch had kept the heal's text
for V8 in settings.rs, docs/process-versions.md and the checklist, so both
changes shared one number. V8 is main's again (its doc comment, its row and
its history entry), and the heal is V9: HealMethod::of, the tests, the GPU
spot test (V8 kernels, V9 on the CPU), the paper and the docs follow.

Also documents Process::version and the spot and grain tests the PR changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 18:03:33 +07:00
P2H 495b27da7f Merge branch 'main' into heal/pinned-fill 2026-11-11 17:00:09 +07:00
cezar 1a301fc2d8 LR-EDIT-LENSBLUR: camera-like Lens Blur with AI subject focus and per-mask bokeh
Part of the Lens Blur row (`LR-EDIT-LENSBLUR`, ⬜ → 🟡: no depth map yet). Related: #377 (SAM 3 subject selection, used here for the Lens Blur focus).

## Problem

Lens Blur settings existed but nothing rendered them: there was no way to add a shallow depth of field, keep the subject sharp while the rest falls out of focus, or blur only part of a photo through a mask.

## Change

**Edit → Lens Blur** (`section.lensBlur`, ⌘6)
- **Apply**, **Amount**, **Boost** (brighter bokeh highlights) and **Transition** (how gradually the blur grows away from what is in focus, so the subject doesn't look cut out).
- **In Focus**: *Subject* (a mask) or a fixed shape: **Auto / Round / Horizontal / Vertical**, buttons drawn in code that work on the light themes.
  - **Move & Resize** (tool `lensBlurShape`) drags the ellipse on the photo and stretches it by its handles. Each drag is one undo step; a shape button puts the ellipse back in the middle.
- **Find Subject** (`lensBlur.findSubject`) runs only when clicked, never automatically on Apply.
  - It starts from the focus point the camera recorded, when the file has one (Sony ILCE-1 and ILCE-7SM3, the models `lightcraft_meta` reads today). Otherwise it starts from the subject estimate.
  - SAM 3 keeps the prominent people and animals: those at the focus point and those of a similar size. When the focus point falls on neither, it falls back to an object click at that point.
  - The result is a normal Object mask ("Lens Blur Subject") that can be refined in Masking.
  - It runs on the background segment worker, and on remote SAM 3 too (`Operation::Subject`). While the mask is pending, the UI shows a spinner and the render keeps the subject estimate in focus, so the photo is never blurred whole.
  - Without the model, it returns the model-missing error, changes nothing, and the UI offers the SAM 3 download.
- **Brush Refinement**: Focus and Blur brushes painted on the photo (`lensBlur.brushStroke`, `lensBlur.brushReset`), with Size, Feather, Flow, Amount and Auto Mask.
- While Apply is off, In Focus, the shapes, Move & Resize and Find Subject are disabled.

**Masking: a Lens Blur block in every mask** (`section:maskLensBlur`, under Refine Edges)
- **Blur: Selection / Outside**. Outside blurs what the mask leaves out, without inverting the mask's other adjustments.
- **Amount**, **Boost** and **Transition**, per mask. The header's eye switches the block off and keeps its values; the header folds the block.
- Stored as `lens_blur`, `lens_blur_outside`, `lens_blur_boost`, `lens_blur_transition` and `lens_blur_off` on `LocalAdjustments`, set through `mask.adjust`.

**Rendering** (`crates/pipeline/src/lens_blur.rs`)
- Runs in the scene-linear stage after denoise; its settings are part of `pre_nr_key`.
- Disc (bokeh) kernel at four levels on coarse grids, with a normalized convolution weighted by the circle of confusion, so sharp areas don't bleed halos into the blur. Transition uses a chamfer distance to the in-focus area.
- The radius is relative to the long edge, so the blur doesn't depend on resolution. The work stays bounded on large exports: the disc kernel has a fixed size, and each level's coarse grid stays within a cell budget.
- Zoomed windows, both 8-bit and deep (16-bit/float), read around them and are cut back to the request. The grids follow the whole output's origin, and the automatic subject estimate is made once from the whole photo. A window therefore matches the whole render.
- GPU path: read back, apply on the CPU, upload (`crates/gpu/src/render.rs`).
- Hostile values (NaN or infinite sizes, out-of-range areas and focus points, oversized stroke lists) are sanitized or rejected, never a panic.

All new strings are in the 17 locales.

**Not in this PR:**
- Real depth. The falloff is the image distance from the focus, not scene depth; a depth model (e.g. Depth Anything V2 Small on candle) would be a separate PR.
- Rotating the ellipse.
- Aperture shapes.
- Focus points for more camera makes and models.
- Find Subject doesn't resume by itself after the SAM 3 download (the Masking tools do). Like the existing Object / Describe jobs, it shows no row in the activity stack.

## How it was checked

- [x] Full `cargo xtask ci` on Windows 11 x86_64 after the latest merge of `main` (465c8722):
  - fmt, clippy, heif, parity, layers, assets and wasm pass;
  - every Lens Blur test passes;
  - the only failures are five tests outside this change that fail on Windows on `main` too: `export::tests::sixteen_bit_zip_tiff_is_never_larger_than_uncompressed`, the two GPU out-of-memory tests in `gpu::ctx`, `dialog_role::settings_is_a_dialog_too` (needs craft-fonts) and `folder_drop::dont_ask_again_moves_the_next_drop_at_once`.
- [x] Tests that fail without the change:
  - **pipeline**:
    - the `lens_blur` tests: shapes and moved or hostile areas, blur growth away from the focus, the fallback while an AI mask is pending, brushes, masks blurring their selection or outside with Transition, hostile input;
    - `large_image_blur_work_is_bounded`: on a 60 MP export with the strongest global and per-mask settings, the disc kernel stays a fixed size and every level's coarse grid stays within its cell budget, including an offset render window;
    - window/full-render parity at U8 and U16, including the automatic subject.
  - **engine**: brushes with undo; Find Subject without the model changes nothing; deleting the focus mask clears the focus; a partial effect preset sets `lens_blur`; with the `sam` feature, Find Subject fills the waiting mask.
  - **segment**: `prominent_subjects`, and remote `Subject` validation.
  - **catalog**: `op_variants_are_versioned` with the new format version.
  - **ui-egui**: the brushes painting on the photo, the shape buttons, the controls disabled while Apply is off, Move & Resize with undo and redo, the mask block (side, sliders, eye, folding).
- [x] User-visible change: ran the app and looked at the result (dark and light themes).

## Screenshots

**Before / after**

<img width="1402" height="952" alt="before" src="https://github.com/user-attachments/assets/8baceb99-7708-4c25-990c-8da29b6bc1b4" />
<img width="1320" height="937" alt="after" src="https://github.com/user-attachments/assets/a1476510-558a-4460-8766-b25bda0dfd3d" />

**Edit → Lens Blur** and **the mask's Lens Blur block**

<img width="457" height="626" alt="main painel" src="https://github.com/user-attachments/assets/47a19637-29a8-4446-a003-2eef416975b7" />
<img width="463" height="333" alt="mask painel" src="https://github.com/user-attachments/assets/345ffc14-66d2-4adc-af3c-b756727201de" />

## Merging

- **Overlap:** #1713 (Clearfall; a draft since 2026-10-14 that conflicts with main) implements the same row on the CPU. It has aperture shapes and XMP roundtrip, which this PR lacks. This PR adds the per-mask block, SAM 3 Find Subject from the camera's focus point, the GPU path and window parity. Only one should land; happy to port what #1713 has that this lacks.
- **Existing edits and libraries:** unchanged. Lens Blur is off by default and every new field is omitted from the JSON at its default, so existing settings keep their JSON and hashes.
- **Shared numbers taken:** catalog format `VERSION` 12 (`crates/catalog/src/journal.rs`). main already uses 10 (`Mask.on_photo`) and 11 (`EmbeddedLens.source`), so Lens Blur takes one past them. If another pull request lands with 12 first, I'll take the next one when I merge main. No render-cache, look or process version change.
- **Where it came from:** own implementation; nothing derived from GPL code or Adobe data. The camera focus point comes from the existing `lightcraft_meta` reader; subject selection uses SAM 3 through the existing segment crate.
- **New dependencies, `unsafe`, build scripts, network access, spawned processes, deleted files, CI or `xtask` gate changes:** none. The remote SAM 3 protocol gains one request (`Operation::Subject`). An older worker rejects it with an error, as `docs/ai-masks.md` notes.

## Checklist

- [x] No new panic path in non-test code
- [x] New text on screen goes through `tr()` with keys in all `locales/*.json`; ⌘6 opens the new section (KEY-SECTIONS)
- [x] `docs/parity-checklist.md` rows updated (LR-EDIT-LENSBLUR 🟡, LR-MASK-SLIDERS, KEY-SECTIONS); `docs/gaps.md` has no Lens Blur entry
- [x] New code has a caller
- [x] No new assets (the shape icons are drawn in code)
- [x] Ready to merge

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
  * Added Lens Blur with adjustable strength, highlight boost, and transition controls, plus Round, Wide, and Tall focus shapes.
  * Keep a subject or selected mask in focus, find people or animals automatically, and refine focus or blur with brushes. Move and resize the focus area directly on the photo.
  * Apply Lens Blur to individual masks, including selections or areas outside them.
* **Bug Fixes**
  * Improved Lens Blur rendering for cropped views and preserved focus-mask assignments correctly when masks are edited.
* **Documentation**
  * Updated feature and control guides, with Lens Blur interface translations added across multiple languages.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 08:02:05 +01:00
Jeremy Hooke bb414d220a LR-EDIT-LIGHT-SHADOWS: fix Highlights/Shadows block artefacts in fine detail; 4× faster GPU median
Fixes #3460
Related: #2936 (slow GPU kernel compiles on Windows/DX12). This PR builds the GPU kernels without wgpu's workgroup-memory zeroing, which took a DX12 release start from ~87 s to 1.4 s on a GTX 1070 with the new median kernels; it may shorten the compiles there too, but does not close it.

## Problem

Raising Shadows on a photo with dark lettering on a bright panel makes bright blocks grow beside the
letters. On a Canon CR3 of a bus (6960×4640) with a black fleet number on a yellow panel, Shadows +75
puts bright yellow rectangles in the gaps where the digits pinch together and inside the 4's counter.
At Shadows +5 there is none of this; at +75 it shows at any zoom. Narrow gaps between dark objects
generally can do it: the pinned corpus has the same thing in the gap between two posts under a machine
(Hasselblad, `coverage-6568.fff`).

## Cause

From process V2 the Highlights/Shadows base (`local::tone_base`) is the edge-aware filter of a
separable median of log luminance, at a radius of 0.15 % of the long edge (10 px here), so that thin
detail (twigs, lines, #632) takes its surroundings' shift. Text strokes and gaps are about that wide,
so each row and column window is close to half letter and half panel, and the median picks one tone
or the other in rectangles: it fills the gaps between the digits and the 4's counter with the letters'
tone. The guided filter keeps those blocks, so panel pixels whose base reads as deep shadow get
Shadows' full lift (`2^(1.7·s·w^1.5)`, up to ~1.3 EV at +75).

## Examples

Top: before, bottom: after.

The fleet number on the bus photo, Whites +54, Blacks +31, Shadows +75, at 300 %:

<img width="1020" height="976" alt="example_photo_pair" src="https://github.com/user-attachments/assets/cc5b164f-612d-4d7d-bda3-db6afd8b177f" />


The gap between two posts in the corpus' Hasselblad `coverage-6568.fff` (CC0, raw.pixls.us),
Shadows +100, at 300 %:

<!-- image: example_corpus_pair.png -->
<img width="900" height="1216" alt="example_corpus_pair" src="https://github.com/user-attachments/assets/feb4b240-194e-40b1-b5b9-c4419f840df6" />

Synthetic lettering at the scale of a bus number in a 7000 px photo, Shadows +75, at 200 %:

<!-- image: example_pair.png -->
<img width="880" height="820" alt="example_pair" src="https://github.com/user-attachments/assets/bd02e600-dda0-4648-85e9-f89ce046eb08" />

## Change

`local::detail_free` (CPU) and its GPU twin: each value of log luminance is clamped between its
separable median at r (as before) and the median of a 3× wider neighbourhood (the median at r of a
box-downscaled copy, enlarged bilinearly, like `guided_fast`'s coefficients). The base is the guided
filter of that plane.

- A twig or speck in an even surround has both medians on the surround's side and takes the nearer,
  as under the median alone (#632 unchanged).
- The gap between two strokes sits in a wider neighbourhood that is mostly panel: the medians
  disagree and the gap keeps its own tone. The strokes themselves count as fine dark detail on the
  panel (both medians agree) and keep their contrast, as twigs do.
- Steps between regions stay exact (the fine median keeps them).
- GPU: the coarse median reuses the box/bilinear resize, plus one `clamp_between_k` map kernel.
  CPU and GPU match (max 1 level).
- GPU median kernels rewritten (`median_h` / `median_v`): each workgroup loads its taps into
  workgroup memory and selects by rank, 4 neighbouring outputs per thread. The old partial selection
  sort over a private 49-tap array sat in scratch memory. Same selection, so bit for bit the CPU's
  (`median_matches_cpu_bit_for_bit`, every r 1–24); renders are byte-identical to the old kernels.
  On 6960×4640 at r = 10 (M2 Max) the median takes 191 → 47 ms.
- GPU kernels are built without wgpu's zeroing of workgroup memory (as `nn.rs` and `faces.rs` already
  are): on DX12 it made FXC take ~87 s over the new median kernels at every start of a release build
  (GTX 1070, 1.4 s without it). Every element of `med_tile` the kernels read is loaded before the barrier;
  renders are byte-identical.
- Cost on the 6960×4640 bus CR3 with Whites +54, Blacks +31, Shadows +75 (M2 Max): GPU planes
  231 ms on `main` → 113 ms here (257 ms with this PR's first kernels); CPU base ~388 → ~453 ms.
  The CPU path enlarges the coarse median while it clamps, into the fine median in place
  (`detail_free_matches_its_reference`, bit for bit).
- New process V8 (`Process::LATEST`). Existing edits keep their process and render as before, so `RENDER_CACHE_VERSION` is unchanged (it is 76 on `main`).
- Docs: `process-versions.md` (V8 row, a paragraph on the lettering fix, revision history), `parity-checklist.md`
  (LR-EDIT-LIGHT-HIGHLIGHTS / -SHADOWS notes).

An earlier revision of this PR clamped each value to the quartiles of its window instead. It fixed
the lettering but stopped treating isolated lines between r/2 and r wide as detail (twigs of 3–6 px
against a dark wall were lifted less than the wall, as under V1), which the corpus run below caught.
A fixed window can't tell an isolated line from a gap between strokes; a wider neighbourhood can.

## Process version

The new base applies from a new process, **V8** (V7 plus `local::detail_free`; `local::base_keeps_gaps` is true from V8, CPU and GPU). v0.19.0 shipped V3 to V6, and crystal grain (#3630) took V7 on `main`, so V1 to V7 render exactly as before: `tests_legacy` still locks V1 and V2, and `only_process_v8_on_takes_the_detail_free_base` checks that every earlier process keeps the plain median. New photos get V8; photos already edited keep the blocks until Update to Current Process.

The faster median kernels and the workgroup-memory change don't change pixels, so they apply to every process. They stay in this PR: the zeroing only costs time on the new median kernels (on `main` the kernels compile in 0.8 s on the GTX 1070), so on its own it would speed up nothing.

## How it was checked

- [x] New test `gaps_between_letters_keep_their_own_tone_in_the_base`: a row of synthetic "8"s
  sized like the bus number. With the median, 360 panel pixels sit more than 1 EV above their base
  (worst 2.25 EV); now none do (worst 0.8 EV). It fails with the median alone.
- [x] New test `isolated_lines_up_to_the_detail_radius_stay_out_of_the_base`: light lines 1–9 px wide
  on a dark ground (r = 10) stay out of the base, as under the median. It fails with the quartile
  clamp (a 6 px line 0.31 of the way into the base).
- [x] New test `detail_free_keeps_steps_and_regions`: steps and flat fields pass through unchanged;
  tiny, empty and NaN planes don't panic.
- [x] The #632 tests (twig/stalk contrast, local contrast, no halo at a strong edge, V1 unchanged)
  and the median reference tests pass unchanged.
- [x] `lightcraft-gpu` integration tests on a real adapter, including
  `highlights_shadows_base_matches_on_every_process` (max difference 1 level).
- [x] Corpus A/B: all 451 pinned raws (`cargo xtask corpus --download`) rendered at full size before
  and after, with Shadows +100 and with Highlights −100 (902 pairs, GPU). No failures. RMSE median
  0.18 % (Shadows) / 0.10 % (Highlights), max 0.86 %; pixels changed by more than 3 % at most 0.07 %
  of a photo; worst 8×8-block change median 10 / 7 levels, 99th percentile 44 / 41, max 61. I looked
  at the 22 largest local changes (old over new, at the worst block): no new artefacts. Most are a
  slightly different tone in small gaps among foliage or branches; one is the Hasselblad gap above.
- [x] User-visible change: rendered the bus photo at full size and at 2400 px with Whites +54,
  Blacks +31 and Shadows +5 / +75, and looked at the number, the plate, foliage against the sky and a
  brick lattice fence.
- [x] New tests `median_matches_cpu_bit_for_bit` (GPU, M2 Max) and `detail_free_matches_its_reference` (CPU).
- [x] After merging `main` and moving the base to V7 (Linux, Ryzen 5 7545U, RADV): `cargo test --release` of `lightcraft-develop`, `-pipeline` (including `tests_legacy`), `-catalog`, `-engine`, and `-gpu` on the real adapter (skipping `running_out_of_device_memory_falls_back_without_stopping_the_gpu`, which fills RAM on an APU; see above); `cargo fmt`, `cargo clippy --workspace --all-targets -D warnings`, `cargo xtask layers`, `roots`, `assets`, `parity` and `wasm`. Not run: the full `cargo xtask ci`, and the macOS-only `tests_light::v1_and_v2_render_as_before_v3` (V1 and V2 don't change, so it shouldn't need re-capturing).
- [x] After merging `main` again (with crystal grain as V7) and moving the base to V8 (Linux, Ryzen 5 7545U, RADV): `cargo test --release` of `lightcraft-develop`, `-pipeline` (including `tests_legacy` and the grain tests), `-catalog`, `-engine`, and `-gpu` on the real adapter (skipping `running_out_of_device_memory_falls_back_without_stopping_the_gpu`); `cargo fmt`, `cargo clippy --workspace --all-targets -D warnings`, `cargo xtask layers`, `roots`, `assets` and `parity`. Not run: `wasm` and the full `cargo xtask ci`.
- [x] `cargo xtask ci --quick` (with `CRAFT_FONTS_DIR`): all steps pass. After the median change: all steps pass again (without `CRAFT_FONTS_DIR`), and the CR3 renders
  byte-identical to the first kernels on GPU and CPU.


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
  * Highlights and Shadows adjustments better preserve clean gaps in fine details such as lettering while maintaining the existing treatment of broader image features.
  * Tone adjustments are less likely to include isolated, narrow lines in the base used for processing.
  * The updated detail handling helps retain fine structure while reducing unwanted influence from closely packed details.
* **Documentation**
  * Updated process notes to explain how fine-detail handling affects Highlights and Shadows adjustments.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 07:31:45 +01:00
Hoang Pham a51aedcd2d LR-REM-HEAL: process V8 pins Heal to the spot's edge in log space, matches the grain, reads sources at whole pixels
Heal (and Remove's heal) added a Gaussian-weighted average of the
difference between photo and source around the spot, in linear light.
It was not pinned to the photo at the spot's edge: spots on gradients
left a faint disc, dark features near a spot that it doesn't touch
smudged in, texture moved across light kept its absolute amplitude
(blotchy in shadows, flat in highlights), and bilinear reads at
fractional source offsets halved the grain.

Process V8 (docs/process-versions.md), so edited photos keep their look
until Update to Current Process:
- the patch is source * e^P, P the membrane fill (inpaint::membrane_fill)
  of the log ratio of photo to source, known only on the ring of pixels
  touching the spot, blurred there over the outside only (1.5 px);
- the source's fine detail is scaled to the detail around the spot
  (ratio of medians, within 0.5 to 2x);
- every spot, Clone included, reads its source at whole pixels;
- the GPU renderer reads the image back for the spot stage on V8 photos
  with spots; V1 to V7 keep the device kernels.

New tests in spots::pinned each also check that the previous heal fails
them; existing spot tests run on both methods; GPU spots_match covers V7
and V8.
2026-11-10 23:32:33 +07:00
Dimitrij Denissenko 26a8f4e706 LR-MASK-BRUSH: Flow as in Lightroom (process V8): coverage per brush radius travelled
Measured in Lightroom Classic on a grey card (#4045), a stroke's centre is
covered by 41 % at Flow 25 and 76 % at Flow 50; here every dab added the
full flow, r/4 apart (closer on a slow drag), so 90 % and over 99 %. From
process V8 a dab adds 1 - (1 - flow)^(d / r) for its distance d from the
previous dab, so a point a stroke passes over for a length L is covered by
1 - (1 - flow)^(L / r) however densely the dabs lie: 44 % and 75 %. CPU,
GPU (a flow per dab in the brush data) and the live stroke alike; V1 to V7
render as before.
2026-11-10 09:07:59 +00:00
Bruno-Alumn 9d765ad2b1 GPU: the window's surface failing to configure no longer sends rendering to the CPU (#4029)
When the renderer adopts the window's device, its uncaptured-error handler replaced the window's
log-only one and stopped the GPU renderer on any error. The renderer's own work runs in error
scopes, so on that device an uncaptured error is the window's: a Surface::configure that fails once
("Failed to wait for GPU to come idle", seen switching desktops on KDE Wayland) disabled GPU
rendering until a restart, with the device fine. An error naming a Surface on the window's device
is now logged; any other still stops the renderer, as does every error on a device of its own, and
a lost device is still caught by the device-lost callback.
2026-11-10 01:38:03 +01:00
helgehelge123 0d4ceb8857 Merge branch 'sam3-gpu-4-detr' into sam3-gpu-5-mask-decoder
Brings in origin/main via the stack. Docs follow main's new header
(changes listed in the revision history only): the branch's
"Last updated / Change" headers give way to it, its revision rows stay,
and target-app-parity gets a row for the mask decoder that was only in
its header before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 01:31:52 +01:00
helgehelge123 b3a178e813 Merge branch 'sam3-gpu-3-necks' into sam3-gpu-4-detr
Brings in origin/main via the stack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 01:29:29 +01:00
helgehelge123 a3a866e925 Merge branch 'sam3-gpu-2-backbone' into sam3-gpu-3-necks
Brings in origin/main via the stack. The integration-test list keeps
both sides' modules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 01:26:43 +01:00
helgehelge123 6beeef483d Merge branch 'sam3-gpu-1-plumbing' into sam3-gpu-2-backbone
Brings in origin/main via the plumbing branch. gpu lib.rs and the
integration-test list keep both sides' modules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 01:24:40 +01:00
helgehelge123 9eed405736 Merge remote-tracking branch 'origin/main' into sam3-gpu-1-plumbing
Locale conflicts resolved key by key: main's entries and order kept,
this branch's added keys inserted after their neighbours.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 01:21:31 +01:00
radialmonster 8246dd00d6 Export: downscale with Lanczos-3 and sharpen with a Gaussian luma USM (#2970)
Exports shrank with the preview's Mitchell filter, which left small exports
(800 px web sizes) visibly soft even with output sharpening on. Exports now
downscale with Lanczos-3 (RenderRequest::downscale = Sharp, CPU and GPU);
previews and thumbnails keep Mitchell.

Output sharpening is an unsharp mask on luma at output scale: a Gaussian of
0.7 / 0.8 / 1.0 output px for screen / glossy / matte, amount x0.5 / x1 /
x1.6 for low / standard / high, with overshoot clamped to 10 % of the local
3x3 range so edges get no halos or colour fringes. Full-size exports keep
their size and, with sharpening off, are bit-identical to before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014ti8KemZbjE2ZgHgV1q1BM
2026-11-07 04:21:03 -05:00
Jeremy Hooke ed10d4486c Merge main into crystal-grain; the crystal grain moves to process V7
v0.19.0 shipped V4 to V6 with value-noise grain, so those stay frozen and
the crystal grain becomes a process of its own. V7 is V6 plus the grain:
without grain it renders as V6 (`without_grain_v7_renders_as_v6`), and the
GPU equivalence cases now cover V6's value noise.

Merged with main's float output (`deep`, `hdr`): the value noise keeps its
clamped luminance; the crystal grain already clamps, and fades out at and
above SDR white. The finish kernel's failed-render check stays ahead of
the aux upload.

The test of unknown process numbers now takes one past the latest: 7 was
hard-coded, and is a known process now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 10:53:18 +11:00
eliets2 8a0b91a95c GPU float output for the HDR render (F32Hdr) (#3856)
* Render HDR rendition on GPU for HDR display drafts

HDR edits on HDR displays currently pay for a second CPU float render on every full render and show only SDR during drags, making slider drags several times slower.

Allow F32Hdr requests through the GPU path with a float output target matching the CPU HDR rendition, and let draft renders carry HDR again instead of being excluded.

Test: gpu_handles_f32hdr_renders_for_hdr_display failed before the change and passes after.

* Issue #2297: float output from the GPU's finish kernel for the HDR render

The kernel wrote 8 bits only, so `handles` taking F32Hdr left no float samples.
It now keeps values up to the edit's peak (highlight desaturation, vignette,
gamut map, curves above SDR white, grain, LUT profiles, as finish_with does),
encodes with the exact sRGB curve as a float render does on the CPU, and writes
three linear floats per pixel into `out`. Written words carry the sign bit, so
work that never ran still fails the render instead of reading as black.

hdr_histogram keeps its Quality::Draft exclusion: it renders on the CPU, and the
UI already runs a small render beside the drafts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: eliets2 <287273517+eliets2@users.noreply.github.com>
Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 17:59:03 +01:00