Files
DarkRoom/core/dr-gpu/src/error.rs
T
dtourolle c6a846a1f9 Brighten her face without touching the sky behind her
A mask layer is an ordinary develop chain plus a rule about where it
applies. Nothing in the chain knows it is being masked, so every operation
that works globally now works locally and a newly declared op in `ops/`
arrives with local support already done.

The composer emits each layer after the global chain and before the
conversion out of camera space, which is what a photographer means by "and
*then* lift the shadows on her face". Op fragments write to a `c` they
expect to own, so a layer block shadows it and copies the result back out
through a carrier — assigning the outer one from inside is impossible
precisely because it is shadowed. The fused dispatch survives: three global
adjustments and two masked ones remain one shader, one read, one write.

Masks rasterise on the GPU and never exist in CPU memory (ARCH §5.4). That
is the whole reason darktable's brush masks lag, and it is architectural
rather than tuning, so it is not a thing to inherit and fix later.

The rasteriser is a render pass rather than the compute shader it obviously
wants to be, and the format is why: R8Unorm is not a core storage format,
so a compute path has to widen masks to four bytes per pixel — 768 MB
across eight layers of a 24 MP export, against 192 MB at one byte. A colour
attachment takes R8Unorm happily. The array slice comes from the attached
view, so no slot uniform exists to disagree with where the pass writes.

Region masks index a compacted label field rather than the watershed's raw
basin roots, because a root is a sparse index into pixel space and
indexing a per-region array by one would need a table the size of the
image. Changing a selection then costs a few kilobytes, not a re-upload.

Stored as region ids, not as pixels: diffable, mergeable per-field under
FR-NC-9, and cheap in a sidecar. The ids only mean anything alongside the
segmentation that produced them, so each layer carries that signature and
is treated as stale rather than applied when it does not match — a
confidently wrong mask being much worse than an absent one.

Seven device tests render actual frames and read them back. The unit tests
either side check halves that would both pass if the two agreed with each
other and were both wrong; a mask sampled with x and y swapped satisfies
them and fails these.
2026-08-22 08:39:16 +02:00

45 lines
1.6 KiB
Rust

/// TRACES: NFR-R7 | NFR-R8
/// Failures from the GPU layer.
///
/// `DeviceLost` is deliberately a distinct variant rather than folded into a
/// generic error: it is an expected event on Android (ARCH §6.10), not an
/// exceptional one, and callers recover from it by rebuilding the device and
/// re-driving from the edit graph.
#[derive(Debug, thiserror::Error)]
pub enum GpuError {
#[error("no suitable GPU adapter found")]
NoAdapter,
#[error("failed to request device: {0}")]
DeviceRequest(String),
#[error("GPU device lost — recreate and re-render from the edit graph")]
DeviceLost,
#[error("shader compilation failed: {0}")]
ShaderCompilation(String),
#[error("readback failed: {0}")]
Readback(String),
/// The CFA layout is one no demosaic here handles — in practice a file
/// `dr-decode` could not identify the pattern of. Reported rather than
/// approximated with the Bayer path, which would produce a maze of colour
/// artefacts and look like a corrupt file.
#[error("unsupported CFA pattern: {0}")]
UnsupportedCfa(String),
#[error("image too large for this device: {0}")]
TooLarge(String),
/// A mask input that cannot describe the image it claims to — a label
/// field whose length disagrees with its own dimensions, most often.
///
/// Its own variant rather than a panic because the caller assembles this
/// from a segmentation and a render size that are computed in different
/// places, and a mismatch between them is a bug worth reporting with its
/// numbers rather than an abort.
#[error("invalid mask input: {0}")]
InvalidMask(String),
}