Let an operation read the pixel next to it, and settle where sharpening belongs
The fused pass hands a fragment a colour and no coordinate. That is what buys one dispatch for a whole edit, and it is also a wall: sharpening, noise reduction, clarity, texture, dehaze and spot removal are each defined by what the neighbours are doing, and FR-DEV-3 and FR-DEV-8 ask for all six. None of them could be written at any price. So there is now a detail stage. An operation implements `Operation` for its parameters exactly as before — the panel, the sidecar, the history and the presets all work unchanged — and additionally returns `Affects::Detail` and a `DetailStage` yielding one pass per dispatch. `Affects` grows the third variant `docs/requirements.md:250` designed and nothing had cut. Where the stage sits is a colour-science decision, not an arrangement of convenience. It runs after every point operation and every mask layer, so an amount chosen against a tone curve survives the curve moving; in linear sRGB after the camera matrix, because camera RGB has no luminance to sharpen against; and before the output transform and the clip, because FR-DEV-2 allows one quantisation and a highlight clipped before a convolution grows a dark ring. The fused pass therefore ends one of two ways, and when a detail stage follows it hands on unclipped f16 and the last detail pass encodes. At render resolution rather than on the source, which is the whole of FR-DSP-1: a pass before the framing prologue would cost 24 MP to draw a 2 MP preview. `RenderScale` is what makes that survivable — a radius is stored as a fraction of the frame's shorter edge, exactly as a mask feather already is, or as a count of source pixels, and converted per render. It also reports when a radius is smaller than a proxy pixel rather than drawing a plausible lie; zooming to 1:1 makes the preview exact with no second path. `Invalidation` gives FR-DEV-3d something to mean. Moving a detail parameter leaves the colour key alone, so `AdjustPass` keeps the linear intermediate and skips the fused dispatch: dragging a sharpening slider costs a convolution. Moving exposure does re-run the detail passes, because they read what the colour pass wrote, and there is no arrangement of keys that avoids it while keeping sharpening after tone. Validated by a separable box blur that is not a develop operation, behind the `detail-probe` feature and absent from a shipping build. An abstraction with no consumer is a guess; a box blur's answer is known in closed form, so the tests assert every byte of the ramp rather than that the edge got softer. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,897 @@
|
||||
//! Neighbourhood operations — the ones that must read a pixel they are not
|
||||
//! writing.
|
||||
//!
|
||||
//! # Why this exists at all
|
||||
//!
|
||||
//! Every operation in [`crate::operation`] contributes a fragment taking a
|
||||
//! `vec3<f32>` and returning one. That contract is what makes the fused
|
||||
//! dispatch possible, and it is also an absolute wall: a fragment is handed a
|
||||
//! colour, not a coordinate, so it cannot look left. Sharpening, noise
|
||||
//! reduction, clarity, texture, dehaze and spot removal are all defined by
|
||||
//! what the *neighbours* are doing, and none of them can be written as a point
|
||||
//! function of `c` at any price.
|
||||
//!
|
||||
//! FR-DEV-3 asks for all six and FR-DEV-8 for spot removal. So the fused pass
|
||||
//! is not the whole pipeline; it is the *point-operation* stage of it, and
|
||||
//! this module is the stage that follows.
|
||||
//!
|
||||
//! # Where it sits, and why there
|
||||
//!
|
||||
//! ```text
|
||||
//! demosaiced source (camera space, full sensor resolution)
|
||||
//! |
|
||||
//! | <- framing prologue: output pixel -> source position
|
||||
//! v
|
||||
//! +------------------------------------------+
|
||||
//! | the fused point-operation pass | one dispatch
|
||||
//! | white balance, exposure, tone, colour |
|
||||
//! | the mask layers |
|
||||
//! | camera RGB -> linear sRGB |
|
||||
//! +------------------------------------------+
|
||||
//! | rgba16float, linear, **unclipped**, at render resolution
|
||||
//! v
|
||||
//! +------------------------------------------+
|
||||
//! | the detail stage - this module | one dispatch per pass
|
||||
//! | sharpen, NR, clarity, texture, spots |
|
||||
//! +------------------------------------------+
|
||||
//! | the last pass applies the output transform
|
||||
//! v
|
||||
//! rgba8unorm display or export texture
|
||||
//! ```
|
||||
//!
|
||||
//! Four things about that position are decisions rather than convenience, and
|
||||
//! each of them could defensibly have gone the other way.
|
||||
//!
|
||||
//! **After tone, not before.** Sharpening before a tone curve and sharpening
|
||||
//! after it are different pictures, not the same picture computed two ways: an
|
||||
//! S-curve steepens the mid-tones, so a halo introduced before it is amplified
|
||||
//! by whatever slope the curve happens to have at that luminance, and the
|
||||
//! amount that looked right stops looking right the moment the curve moves.
|
||||
//! After the curve, the amount the user chose is the amount they see, and it
|
||||
//! survives every later change to tone. This is also what ARCH §5.2 draws:
|
||||
//! texture, clarity, spot removal and sharpen/NR sit below the tone curve and
|
||||
//! the colour mixer.
|
||||
//!
|
||||
//! **In linear light, after the camera matrix.** The fused pass works in
|
||||
//! *camera* space, because white balance and exposure are physically
|
||||
//! meaningful there and nowhere else. A detail pass is the opposite case: it
|
||||
//! wants a luminance, and camera RGB has no luminance — the three channels are
|
||||
//! whatever the CFA's dyes passed, and weighting them 0.2126/0.7152/0.0722
|
||||
//! would be numerology. So the split is taken *after* the `cam_to_srgb`
|
||||
//! multiply, where the working space is linear sRGB and a luminance is a
|
||||
//! luminance.
|
||||
//!
|
||||
//! **Before the output transform, and before the clip.** FR-DEV-2 allows
|
||||
//! exactly one quantisation, at the display or export stage. A detail pass
|
||||
//! reading an 8-bit display-encoded texture and writing another one would
|
||||
//! quantise twice and do its arithmetic in a space where a difference of one
|
||||
//! code value means different things at different brightnesses — which is how
|
||||
//! sharpening ends up with visible banding in a sky. The intermediate is
|
||||
//! therefore `rgba16float` and holds linear values that have **not** been
|
||||
//! clamped to `0..=1`: a recovered highlight is still above one at this point,
|
||||
//! and clipping it before the sharpener sees it would put a hard edge exactly
|
||||
//! where the sharpener is most visible. The last detail pass performs the
|
||||
//! primaries conversion, the clip and the encode, so the single quantisation
|
||||
//! stays single.
|
||||
//!
|
||||
//! **After framing, at render resolution.** The alternative — running detail
|
||||
//! on the demosaiced source before the framing prologue — is superficially
|
||||
//! attractive, because a radius in sensor pixels would then mean exactly what
|
||||
//! it says. It is unaffordable: the source is the full sensor, so a detail
|
||||
//! pass there costs 24 MP of work for a 2 MP preview and FR-DSP-1 stops being
|
||||
//! true. Running at render resolution instead makes the cost proportional to
|
||||
//! what is on screen, and pushes the whole difficulty into one place — the
|
||||
//! scale — which [`RenderScale`] exists to make explicit rather than implicit.
|
||||
//!
|
||||
//! # What this stage deliberately cannot do
|
||||
//!
|
||||
//! **There is no per-mask detail.** A mask layer's chain is fused into the
|
||||
//! point-operation pass; the detail stage runs once, afterwards, over the
|
||||
//! whole frame. Local sharpening is therefore not expressible here, and
|
||||
//! [`crate::mask::MaskLayer::active_ops`] filters detail operations out rather
|
||||
//! than emitting a block that would silently do nothing. Making it possible
|
||||
//! means giving a detail pass the mask array and a layer index, which is a
|
||||
//! change to this module's shader preamble and not to its shape — but it is
|
||||
//! not done, and a caller should not assume it.
|
||||
//!
|
||||
//! # Adding a neighbourhood operation
|
||||
//!
|
||||
//! Declare it in `ops/<id>.yaml` with `rust:`, exactly as the tone curve does
|
||||
//! — the schema in `ops/README.md` describes a point function, and stretching
|
||||
//! it to cover kernels would be a worse language than Rust aimed at one
|
||||
//! caller. Then implement [`crate::Operation`] as usual for the parameters,
|
||||
//! descriptor and sidecar, and additionally:
|
||||
//!
|
||||
//! ```ignore
|
||||
//! impl Operation for Sharpen {
|
||||
//! fn affects(&self) -> Affects { Affects::Detail }
|
||||
//! fn detail(&self) -> Option<&dyn DetailStage> { Some(self) }
|
||||
//! fn wgsl_body(&self) -> String { String::new() } // never called
|
||||
//! // ... descriptor, set_param, param, is_active exactly as usual
|
||||
//! }
|
||||
//!
|
||||
//! impl DetailStage for Sharpen {
|
||||
//! fn passes(&self, scale: RenderScale) -> Vec<DetailPass> { /* ... */ }
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! Everything else arrives unchanged and for free: the develop panel builds
|
||||
//! its controls from the descriptor, the sidecar persists the parameters, the
|
||||
//! history and the presets carry them, and an operation at its defaults
|
||||
//! contributes no pass at all.
|
||||
|
||||
use std::fmt::Write as _;
|
||||
|
||||
use dr_types::ColourSpace;
|
||||
|
||||
use crate::operation::{Helper, Operation, Uniform};
|
||||
|
||||
/// Floats the generated detail uniform block always carries, before an
|
||||
/// operation's own.
|
||||
///
|
||||
/// One `vec4`, which is also the smallest a WGSL uniform struct can be and
|
||||
/// stay aligned. See [`compose_detail`] for what the lanes hold.
|
||||
pub const DETAIL_BASE_UNIFORM_FIELDS: usize = 4;
|
||||
|
||||
/// TRACES: FR-DSP-1
|
||||
/// The relationship between the resolution an edit is being **rendered** at
|
||||
/// and the resolution it will eventually be **exported** at.
|
||||
///
|
||||
/// # The problem this type is the answer to
|
||||
///
|
||||
/// A point operation is scale-free. Exposure is a multiply, and multiplying by
|
||||
/// two is multiplying by two whether the frame is 2 000 pixels wide or 24 000.
|
||||
/// Every operation in the fused pass has this property, which is why nothing
|
||||
/// in the pipeline has needed to know its own resolution until now.
|
||||
///
|
||||
/// A neighbourhood operation has no such luck. "Sharpen with a radius of one
|
||||
/// pixel" is a statement about a specific grid, and the develop view is not
|
||||
/// rendering on that grid — FR-DSP-1 has it rendering at whatever the viewport
|
||||
/// needs, which for a 60 MP frame in a 2 000 px panel is one render pixel per
|
||||
/// nine source pixels. Tune a radius there, export at full size, and the
|
||||
/// exported file is sharpened at a ninth of the strength the photographer
|
||||
/// chose. That is not a rounding difference; it is a different photograph.
|
||||
///
|
||||
/// # The rule
|
||||
///
|
||||
/// **A length is stored normalised and converted here.** Never store pixels in
|
||||
/// an edit. This is not a new idea in this codebase — [`crate::mask`] already
|
||||
/// does it, storing every feather and morphology radius as a fraction of the
|
||||
/// frame's shorter edge and multiplying up in `dr-gpu` at whatever size the
|
||||
/// mask is being rasterised at (see `MaskLayer::feather`, and
|
||||
/// `field_short_edge` in `dr-gpu`'s mask pass). A detail operation follows the
|
||||
/// same rule through [`Self::frame_fraction`] and gets the same guarantee: the
|
||||
/// effect covers the same *proportion* of the picture at every size, so what
|
||||
/// was tuned on screen is what lands in the file.
|
||||
///
|
||||
/// # Two units, because there are two kinds of length
|
||||
///
|
||||
/// The mask rule is not quite enough on its own, because detail operations
|
||||
/// split into two families that mean different things by "radius":
|
||||
///
|
||||
/// - **Compositional** — clarity, texture, dehaze. The radius is a fraction of
|
||||
/// the picture, tens of pixels at any size, and [`Self::frame_fraction`] is
|
||||
/// exactly right. These preview faithfully at any scale.
|
||||
///
|
||||
/// - **Acutance** — capture sharpening, luminance noise reduction. The radius
|
||||
/// is a property of the *sensor*: it is about the lens's circle of confusion
|
||||
/// and the demosaic's interpolation, both measured in source pixels and
|
||||
/// neither of which cares how large the viewport is.
|
||||
/// [`Self::source_pixels`] converts one of those into render pixels.
|
||||
///
|
||||
/// # The honest limit
|
||||
///
|
||||
/// For the second family the conversion runs out. At a one-ninth proxy a
|
||||
/// 1.0-source-pixel radius is 0.11 render pixels, and there is no kernel that
|
||||
/// represents a ninth of a pixel — the information the sharpener would act on
|
||||
/// was thrown away by the downscale before the pass ever ran. No arrangement
|
||||
/// of this stage recovers it, which is why every editor that has shipped tells
|
||||
/// the photographer to judge sharpening at 1:1, and why Lightroom's detail
|
||||
/// panel contains a 1:1 loupe rather than a scaled preview.
|
||||
///
|
||||
/// [`Self::resolves`] reports that condition instead of hiding it, so an
|
||||
/// operation can fade itself out and an interface can say "zoom to 100% to
|
||||
/// judge this" — which is the truth, and better than a preview that lies.
|
||||
/// Zooming is enough: the framing's view rect shrinks while the render target
|
||||
/// keeps its size, so [`Self::ratio`] climbs back to 1.0 at 1:1 and the
|
||||
/// preview becomes exact, with no separate full-resolution path to maintain.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct RenderScale {
|
||||
render: (u32, u32),
|
||||
full: (u32, u32),
|
||||
}
|
||||
|
||||
impl RenderScale {
|
||||
/// `render` is the size being rendered now; `full` is the size the same
|
||||
/// framed region would have at source resolution.
|
||||
///
|
||||
/// Both describe *the region being looked at*, not the whole photograph —
|
||||
/// so a crop and a zoom are already accounted for by the time they arrive.
|
||||
/// [`crate::EditGraph::render_scale`] works both out from the framing, and
|
||||
/// is what a caller should normally use.
|
||||
pub fn new(render: (u32, u32), full: (u32, u32)) -> Self {
|
||||
Self {
|
||||
render: (render.0.max(1), render.1.max(1)),
|
||||
full: (full.0.max(1), full.1.max(1)),
|
||||
}
|
||||
}
|
||||
|
||||
/// A scale that is already at source resolution — an export, or a 1:1
|
||||
/// view. [`Self::ratio`] is 1.0 and nothing is approximated.
|
||||
pub fn full(render: (u32, u32)) -> Self {
|
||||
Self::new(render, render)
|
||||
}
|
||||
|
||||
pub fn render_size(&self) -> (u32, u32) {
|
||||
self.render
|
||||
}
|
||||
|
||||
pub fn full_size(&self) -> (u32, u32) {
|
||||
self.full
|
||||
}
|
||||
|
||||
/// Render pixels per source pixel. 1.0 at export, below 1.0 on a proxy.
|
||||
///
|
||||
/// Averaged over the two axes rather than taken from one. They agree to
|
||||
/// within a pixel by construction — both sizes describe the same rectangle
|
||||
/// — but each is separately rounded to an integer, and taking the mean
|
||||
/// stops a narrow viewport disagreeing with itself.
|
||||
pub fn ratio(&self) -> f32 {
|
||||
let x = self.render.0 as f32 / self.full.0 as f32;
|
||||
let y = self.render.1 as f32 / self.full.1 as f32;
|
||||
(x + y) * 0.5
|
||||
}
|
||||
|
||||
/// Whether this render is smaller than the file it stands for.
|
||||
pub fn is_proxy(&self) -> bool {
|
||||
self.ratio() < 0.999
|
||||
}
|
||||
|
||||
/// A length stated in **source pixels**, in render pixels.
|
||||
///
|
||||
/// For the acutance family — sharpening, luminance NR — whose radius is a
|
||||
/// property of the sensor rather than of the composition.
|
||||
pub fn source_pixels(&self, radius: f32) -> f32 {
|
||||
radius * self.ratio()
|
||||
}
|
||||
|
||||
/// A length stated as a **fraction of the frame's shorter edge**, in
|
||||
/// render pixels.
|
||||
///
|
||||
/// For the compositional family — clarity, texture, dehaze — and the same
|
||||
/// unit `dr-gpu`'s mask rasteriser already converts feathers in. An edit
|
||||
/// stored this way is resolution-independent by construction.
|
||||
pub fn frame_fraction(&self, fraction: f32) -> f32 {
|
||||
fraction * self.render.0.min(self.render.1) as f32
|
||||
}
|
||||
|
||||
/// Whether a radius stated in source pixels survives this render.
|
||||
///
|
||||
/// False means the effect is smaller than a pixel here and whatever is
|
||||
/// drawn is a guess. Report it; do not paper over it — see the type's
|
||||
/// documentation for why there is nothing better to do.
|
||||
pub fn resolves(&self, radius_in_source_pixels: f32) -> bool {
|
||||
self.source_pixels(radius_in_source_pixels) >= 1.0
|
||||
}
|
||||
}
|
||||
|
||||
/// One dispatch of a neighbourhood operation.
|
||||
///
|
||||
/// An operation returns as many of these as it needs. A separable Gaussian is
|
||||
/// two — horizontal then vertical — and gets the ping-pong between them for
|
||||
/// free; an unsharp mask wanting its blur held alongside the original would be
|
||||
/// more, and is the case this shape exists to leave room for.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct DetailPass {
|
||||
/// A short name, used to label the GPU pass and to make a shader
|
||||
/// compilation failure say which of an operation's passes broke.
|
||||
pub label: &'static str,
|
||||
|
||||
/// The furthest this pass reads from the pixel it writes, in **render**
|
||||
/// pixels.
|
||||
///
|
||||
/// Declared rather than inferred from the WGSL, because nothing can infer
|
||||
/// it from the WGSL: the offsets are computed at runtime from uniforms.
|
||||
/// It is the halo a tile has to be grown by before this pass can be
|
||||
/// computed tile-wise (ARCH §5.3), and it is the reason a detail operation
|
||||
/// is not simply "some more shader code" — the scheduler has to know how
|
||||
/// far the dependency reaches before it can schedule anything at all.
|
||||
///
|
||||
/// An understated radius shows as a seam at every tile boundary, which is
|
||||
/// the kind of artefact that looks like a driver bug. State it honestly.
|
||||
pub radius: u32,
|
||||
|
||||
/// The WGSL body.
|
||||
///
|
||||
/// Reads and writes `c`, a `vec3<f32>` of **linear sRGB**, pre-loaded with
|
||||
/// this pixel's own value. Also in scope:
|
||||
///
|
||||
/// - `coord: vec2<i32>` — this pixel.
|
||||
/// - `tap(coord, offset) -> vec3<f32>` — a neighbour, clamped to the edge
|
||||
/// of the image, which is what makes a kernel at the border average the
|
||||
/// pixels that exist rather than fade into black.
|
||||
/// - `render_dims: vec2<f32>` and `render_scale: f32` — the size being
|
||||
/// rendered and [`RenderScale::ratio`], for the rare pass that needs
|
||||
/// them in the shader. Prefer computing lengths on the CPU in
|
||||
/// [`DetailStage::passes`], where the units are named methods rather
|
||||
/// than an untyped float.
|
||||
///
|
||||
/// Uniforms are addressed by the bare names declared in [`Self::uniforms`],
|
||||
/// exactly as a fused fragment addresses its own; the composer rewrites
|
||||
/// them to their prefixed struct fields.
|
||||
///
|
||||
/// **Values are not clipped.** A recovered highlight arrives above 1.0 and
|
||||
/// an out-of-gamut colour can arrive below 0.0. That is deliberate — see
|
||||
/// the module documentation — and a kernel that assumes `0..=1` will
|
||||
/// produce dark rings around specular highlights.
|
||||
pub wgsl: String,
|
||||
|
||||
/// Uniform values this pass's body reads.
|
||||
pub uniforms: Vec<Uniform>,
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3 | FR-DEV-8
|
||||
/// An operation that reads pixels other than the one it is writing.
|
||||
///
|
||||
/// Implemented *alongside* [`Operation`], never instead of it: the parameters,
|
||||
/// the descriptor, the panel controls and the sidecar all come from the
|
||||
/// `Operation` half, and only the execution differs. An operation that
|
||||
/// implements this must also return [`crate::Affects::Detail`] from
|
||||
/// `affects()` and `Some(self)` from `Operation::detail()` — the three are
|
||||
/// checked against each other by a test in [`crate::operation`], because an
|
||||
/// operation that forgot one of them would be dropped from both stages and
|
||||
/// simply not happen, with no error anywhere.
|
||||
pub trait DetailStage: Send + Sync {
|
||||
/// The passes to run, in order, at this resolution.
|
||||
///
|
||||
/// Called per render, so the operation sees the scale it is actually being
|
||||
/// asked to draw at and converts its own lengths here — in Rust, where
|
||||
/// [`RenderScale`]'s two conversions are named after the two units, rather
|
||||
/// than in WGSL where both would be a bare `f32`.
|
||||
///
|
||||
/// Returning an empty vector means "nothing to do at this scale", which is
|
||||
/// the honest answer for an acutance operation on a heavy proxy. It is
|
||||
/// **not** how an operation says it is neutral: that is `is_active()`, and
|
||||
/// an inactive operation is never asked.
|
||||
fn passes(&self, scale: RenderScale) -> Vec<DetailPass>;
|
||||
}
|
||||
|
||||
/// One compile-ready detail pass: complete WGSL and the uniform block for it.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ComposedDetailPass {
|
||||
/// `<op id>/<pass label>`, for GPU labels and error messages.
|
||||
pub label: String,
|
||||
/// Complete, compilable WGSL.
|
||||
pub source: String,
|
||||
/// Uniform values in the order the generated struct declares them.
|
||||
pub uniforms: Vec<f32>,
|
||||
/// See [`DetailPass::radius`].
|
||||
pub radius: u32,
|
||||
/// Whether this pass writes the display/export texture rather than another
|
||||
/// linear intermediate.
|
||||
///
|
||||
/// True for exactly the last pass in the chain, which carries the output
|
||||
/// transform — the primaries conversion, the clip and the encode that the
|
||||
/// fused pass performs when there is no detail stage at all. Folding them
|
||||
/// into the last pass rather than adding a resolve dispatch keeps the cost
|
||||
/// of the stage at one dispatch per pass, not one plus one.
|
||||
pub writes_output: bool,
|
||||
/// Identifies this pass's *structure*, for the pipeline cache. Covers the
|
||||
/// generated source, not the uniform values — so moving a slider uploads a
|
||||
/// buffer and reuses the compiled pipeline, exactly as the fused pass does.
|
||||
pub structure_hash: u64,
|
||||
}
|
||||
|
||||
/// The detail stage of one edit, at one resolution.
|
||||
#[derive(Debug, Clone, Default, PartialEq)]
|
||||
pub struct ComposedDetail {
|
||||
pub passes: Vec<ComposedDetailPass>,
|
||||
}
|
||||
|
||||
impl ComposedDetail {
|
||||
/// Whether the edit has no detail stage — the common case, and the one
|
||||
/// that must cost nothing.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.passes.is_empty()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.passes.len()
|
||||
}
|
||||
|
||||
/// The widest halo any pass needs, in render pixels (ARCH §5.3).
|
||||
pub fn radius(&self) -> u32 {
|
||||
self.passes.iter().map(|p| p.radius).max().unwrap_or(0)
|
||||
}
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3 | FR-DSP-1
|
||||
/// Generate the detail stage for a set of operations at one resolution.
|
||||
///
|
||||
/// Operations that declare no [`DetailStage`], or that are at their neutral
|
||||
/// settings, contribute nothing — the same rule the fused composer follows, so
|
||||
/// an edit with no sharpening produces an empty chain and `dr-gpu` runs the
|
||||
/// single dispatch it always did.
|
||||
///
|
||||
/// `output` is the space the **last** pass encodes into, and it is a parameter
|
||||
/// for the same reason it is a parameter to [`crate::compose_with_framing`]: a
|
||||
/// screen render and a Display P3 export are the same edit and different
|
||||
/// shaders, and neither is more authoritative than the other.
|
||||
///
|
||||
/// # The generated uniform block
|
||||
///
|
||||
/// A fixed `vec4` first, then the pass's own scalars, prefixed with the
|
||||
/// operation id so that a pass never has to know what else is in the block.
|
||||
/// The lanes of the leading `vec4` are, in order: render width, render height,
|
||||
/// [`RenderScale::ratio`], and the pass's index within its operation. The
|
||||
/// first three reach the body as `render_dims` and `render_scale`; the fourth
|
||||
/// is there because a two-pass operation emitting one body for both directions
|
||||
/// is a reasonable thing to want, and would otherwise need a uniform of its
|
||||
/// own purely to say which half it is in.
|
||||
pub fn compose_detail(
|
||||
ops: &[Box<dyn Operation>],
|
||||
scale: RenderScale,
|
||||
output: ColourSpace,
|
||||
) -> ComposedDetail {
|
||||
// Every pass of every active detail operation, flattened, carrying the
|
||||
// operation it came from for the uniform prefix and the helper set.
|
||||
let mut planned: Vec<(&'static str, &'static [Helper], DetailPass, usize)> = Vec::new();
|
||||
for op in ops {
|
||||
if !op.is_active() {
|
||||
continue;
|
||||
}
|
||||
let Some(stage) = op.detail() else {
|
||||
continue;
|
||||
};
|
||||
let id = op.descriptor().id.0;
|
||||
for (index, pass) in stage.passes(scale).into_iter().enumerate() {
|
||||
planned.push((id, op.helpers(), pass, index));
|
||||
}
|
||||
}
|
||||
|
||||
let last = planned.len().saturating_sub(1);
|
||||
let passes = planned
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(position, (id, helpers, pass, index))| {
|
||||
compose_one(id, helpers, &pass, index, scale, output, position == last)
|
||||
})
|
||||
.collect();
|
||||
|
||||
ComposedDetail { passes }
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn compose_one(
|
||||
id: &str,
|
||||
helpers: &[Helper],
|
||||
pass: &DetailPass,
|
||||
index: usize,
|
||||
scale: RenderScale,
|
||||
output: ColourSpace,
|
||||
writes_output: bool,
|
||||
) -> ComposedDetailPass {
|
||||
let prefix = format!("{}_{index}", crate::operation::sanitise(id));
|
||||
|
||||
let mut uniform_fields = String::from(
|
||||
" // x, y: the size being rendered. z: render pixels per source\n\
|
||||
\x20 // pixel — 1.0 at export, less on a proxy (FR-DSP-1). w: which\n\
|
||||
\x20 // pass of this operation this is.\n\
|
||||
\x20 detail_base: vec4<f32>,\n",
|
||||
);
|
||||
let (rw, rh) = scale.render_size();
|
||||
let mut uniform_values = vec![rw as f32, rh as f32, scale.ratio(), index as f32];
|
||||
debug_assert_eq!(uniform_values.len(), DETAIL_BASE_UNIFORM_FIELDS);
|
||||
|
||||
if !pass.uniforms.is_empty() {
|
||||
let _ = writeln!(uniform_fields, " // {id}/{}", pass.label);
|
||||
}
|
||||
for u in &pass.uniforms {
|
||||
let _ = writeln!(uniform_fields, " {prefix}_{}: f32,", u.name);
|
||||
uniform_values.push(u.value);
|
||||
}
|
||||
|
||||
// A uniform struct whose size is not a multiple of 16 is rejected by the
|
||||
// WGSL uniform address space rules — the same padding the fused composer
|
||||
// applies, for the same reason.
|
||||
let pad = (4 - (uniform_values.len() % 4)) % 4;
|
||||
for i in 0..pad {
|
||||
let _ = writeln!(uniform_fields, " _pad{i}: f32,");
|
||||
uniform_values.push(0.0);
|
||||
}
|
||||
|
||||
let mut body = pass.wgsl.clone();
|
||||
for u in &pass.uniforms {
|
||||
body = crate::operation::rewrite_uniform(&body, u.name, &format!("u.{prefix}_{}", u.name));
|
||||
}
|
||||
|
||||
let mut helper_src = String::new();
|
||||
let mut seen: Vec<&str> = Vec::new();
|
||||
for h in helpers {
|
||||
if seen.contains(&h.name) {
|
||||
continue;
|
||||
}
|
||||
seen.push(h.name);
|
||||
let _ = writeln!(helper_src, "{}\n", h.source.trim_end());
|
||||
}
|
||||
|
||||
// The storage format and the tail are the *only* difference between an
|
||||
// intermediate pass and the final one. Everything above — the taps, the
|
||||
// uniforms, the body — is identical, which is what lets an operation write
|
||||
// one kernel without knowing whether it happens to be last in the chain.
|
||||
let (store_format, tail) = if writes_output {
|
||||
(
|
||||
"rgba8unorm",
|
||||
format!(
|
||||
"{} // Clip to the output gamut and encode. The one quantisation\n\
|
||||
\x20 // the pipeline performs (FR-DEV-2), and it is here rather than\n\
|
||||
\x20 // in the fused pass because this is now the last thing to run.\n\
|
||||
\x20 c = clamp(c, vec3<f32>(0.0), vec3<f32>(1.0));\n\
|
||||
\x20 textureStore(output, coord, vec4<f32>(encode_output(c), 1.0));",
|
||||
crate::operation::primaries_conversion(output)
|
||||
),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
"rgba16float",
|
||||
" // Another linear intermediate: no clip and no encode, because\n\
|
||||
\x20 // the pass after this one still has to read real values.\n\
|
||||
\x20 textureStore(output, coord, vec4<f32>(c, 1.0));"
|
||||
.to_string(),
|
||||
)
|
||||
};
|
||||
|
||||
let encode_fn = if writes_output {
|
||||
crate::operation::encode_output_fn(output)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
let label = format!("{id}/{}", pass.label);
|
||||
let indented = body
|
||||
.lines()
|
||||
.map(|l| format!(" {l}"))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n");
|
||||
let source = format!(
|
||||
"// GENERATED — do not edit.
|
||||
//
|
||||
// Detail pass `{label}` — a neighbourhood operation, which is why it is a
|
||||
// dispatch of its own rather than a block in the fused shader: it reads pixels
|
||||
// it is not writing, and the fused contract hands a fragment a colour with no
|
||||
// way back to a coordinate.
|
||||
//
|
||||
// In: linear sRGB, scene-referred, **unclipped**, at render resolution.
|
||||
// Out: {}
|
||||
|
||||
struct Params {{
|
||||
{uniform_fields}}}
|
||||
|
||||
@group(0) @binding(0) var source: texture_2d<f32>;
|
||||
@group(0) @binding(1) var<uniform> u: Params;
|
||||
@group(0) @binding(2) var output: texture_storage_2d<{store_format}, write>;
|
||||
|
||||
// A neighbour, clamped to the edge of the image.
|
||||
//
|
||||
// Clamped rather than zero-filled: a kernel straddling the border must average
|
||||
// the pixels that exist. Returning zero there darkens every edge by a band the
|
||||
// width of the radius, which reads as a vignette nobody asked for and is the
|
||||
// classic way a first convolution goes wrong.
|
||||
fn tap(coord: vec2<i32>, offset: vec2<i32>) -> vec3<f32> {{
|
||||
let last = vec2<i32>(textureDimensions(source)) - vec2<i32>(1);
|
||||
return textureLoad(source, clamp(coord + offset, vec2<i32>(0), last), 0).rgb;
|
||||
}}
|
||||
|
||||
{helper_src}{encode_fn}
|
||||
@compute @workgroup_size(8, 8, 1)
|
||||
fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{
|
||||
let dims = textureDimensions(output);
|
||||
if (gid.x >= dims.x || gid.y >= dims.y) {{
|
||||
return;
|
||||
}}
|
||||
|
||||
let coord = vec2<i32>(gid.xy);
|
||||
// What this render is, relative to the export it has to match.
|
||||
let render_dims = u.detail_base.xy;
|
||||
let render_scale = u.detail_base.z;
|
||||
|
||||
var c = tap(coord, vec2<i32>(0));
|
||||
|
||||
{{
|
||||
{indented}
|
||||
}}
|
||||
|
||||
{tail}
|
||||
}}
|
||||
",
|
||||
if writes_output {
|
||||
"display-encoded, in the output space."
|
||||
} else {
|
||||
"linear sRGB, for the next pass."
|
||||
},
|
||||
);
|
||||
|
||||
let structure_hash = crate::operation::hash_source(&source);
|
||||
|
||||
ComposedDetailPass {
|
||||
label,
|
||||
source,
|
||||
uniforms: uniform_values,
|
||||
radius: pass.radius,
|
||||
writes_output,
|
||||
structure_hash,
|
||||
}
|
||||
}
|
||||
|
||||
// Compiled for this crate's own tests as well as for the feature, so that
|
||||
// `cargo test -p dr-pipeline` exercises the seam whether or not anybody
|
||||
// downstream remembered to turn the feature on. A test that quietly does not
|
||||
// exist is worse than no test, because the absence looks like a pass.
|
||||
#[cfg(any(test, feature = "detail-probe"))]
|
||||
pub mod probe;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_full_render_approximates_nothing() {
|
||||
let s = RenderScale::full((2000, 1300));
|
||||
assert!(!s.is_proxy());
|
||||
assert!((s.ratio() - 1.0).abs() < 1e-6);
|
||||
// A one-pixel sharpening radius is one pixel at export, always.
|
||||
assert!((s.source_pixels(1.0) - 1.0).abs() < 1e-6);
|
||||
assert!(s.resolves(1.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_proxy_shrinks_a_source_length_and_says_so() {
|
||||
// A 6000px frame in a 1500px panel: four source pixels per render
|
||||
// pixel, so a 1px capture-sharpening radius is a quarter of a render
|
||||
// pixel and cannot be drawn. This is the case the whole type exists
|
||||
// for, and the answer has to be "no", not a plausible-looking number.
|
||||
let s = RenderScale::new((1500, 1000), (6000, 4000));
|
||||
assert!(s.is_proxy());
|
||||
assert!((s.ratio() - 0.25).abs() < 1e-6);
|
||||
assert!(!s.resolves(1.0), "a quarter of a pixel is not a kernel");
|
||||
assert!(s.resolves(4.0), "four source pixels do survive");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_frame_fraction_is_the_same_proportion_at_every_size() {
|
||||
// The mask rule, restated as a test: 1% of the shorter edge is 1% of
|
||||
// the shorter edge whether the render is a thumbnail or an export.
|
||||
// This is what makes a clarity radius tuned on screen correct in the
|
||||
// exported file.
|
||||
let proxy = RenderScale::new((2000, 1333), (6000, 4000));
|
||||
let export = RenderScale::full((6000, 4000));
|
||||
let as_fraction = |s: &RenderScale| {
|
||||
let (w, h) = s.render_size();
|
||||
s.frame_fraction(0.01) / w.min(h) as f32
|
||||
};
|
||||
assert!((as_fraction(&proxy) - as_fraction(&export)).abs() < 1e-6);
|
||||
// And in absolute terms it really does scale with the render.
|
||||
assert!((proxy.frame_fraction(0.01) - 13.33).abs() < 0.5);
|
||||
assert!((export.frame_fraction(0.01) - 40.0).abs() < 0.5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zooming_to_one_to_one_makes_the_preview_exact() {
|
||||
// The reason there is no separate full-resolution preview path: the
|
||||
// framing's view rect shrinks while the render target keeps its size,
|
||||
// so the ratio climbs back to 1.0 and a sharpening radius means
|
||||
// exactly what it will mean in the file.
|
||||
let fit = RenderScale::new((2000, 1333), (6000, 4000));
|
||||
let one_to_one = RenderScale::new((2000, 1333), (2000, 1333));
|
||||
assert!(!fit.resolves(1.0));
|
||||
assert!(one_to_one.resolves(1.0));
|
||||
}
|
||||
|
||||
use crate::detail::probe::BoxBlur;
|
||||
use crate::operation::{compose_full, OutputMode};
|
||||
|
||||
fn with_blur(radius: f32) -> Vec<Box<dyn Operation>> {
|
||||
let mut ops = crate::ops::chain();
|
||||
ops.push(Box::new(BoxBlur::with_radius(radius)));
|
||||
ops
|
||||
}
|
||||
|
||||
fn fused(ops: &[Box<dyn Operation>]) -> crate::ComposedShader {
|
||||
compose_full(
|
||||
ops,
|
||||
&crate::Framing::new(),
|
||||
dr_types::ColourSpace::Srgb,
|
||||
&crate::mask::MaskStack::new(),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_detail_operation_contributes_nothing_to_the_fused_shader() {
|
||||
// The seam itself: a neighbourhood operation is in the graph, is
|
||||
// active, and yet emits no block in the single dispatch — because it
|
||||
// physically cannot, and asking it for one would produce an empty
|
||||
// block that reads as an operation doing nothing.
|
||||
let shader = fused(&with_blur(0.05));
|
||||
assert!(
|
||||
!shader.source.contains("---- detail_probe ----"),
|
||||
"a detail operation must not appear as a fused fragment"
|
||||
);
|
||||
assert!(
|
||||
!shader.source.contains("detail_probe_radius"),
|
||||
"nor should it occupy a slot in the fused uniform block"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_active_detail_operation_makes_the_fused_pass_hand_on_linear_values() {
|
||||
// The other half of the same decision. With no detail stage the fused
|
||||
// pass encodes and quantises, exactly as it always has; with one, it
|
||||
// stops at linear working values and the detail chain finishes the
|
||||
// job. Getting this wrong is not a subtle wrong colour — it is a
|
||||
// storage format that does not match the texture bound to it.
|
||||
let neutral = fused(&with_blur(0.0));
|
||||
assert_eq!(neutral.output_mode, OutputMode::Encoded);
|
||||
assert!(neutral.source.contains("texture_storage_2d<rgba8unorm"));
|
||||
assert!(neutral.source.contains("encode_output"));
|
||||
|
||||
let blurring = fused(&with_blur(0.05));
|
||||
assert_eq!(blurring.output_mode, OutputMode::LinearWorking);
|
||||
assert!(blurring.source.contains("texture_storage_2d<rgba16float"));
|
||||
assert!(
|
||||
!blurring.source.contains("fn encode_output"),
|
||||
"the fused pass must not encode when a detail stage follows: \
|
||||
FR-DEV-2 allows exactly one quantisation"
|
||||
);
|
||||
assert!(
|
||||
!blurring.source.contains("clamp(c, vec3<f32>(0.0)"),
|
||||
"nor clip, or the sharpener sees a hard edge at every highlight"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_neutral_detail_operation_costs_the_edit_nothing() {
|
||||
// The rule the whole pipeline is built on, extended to this stage: an
|
||||
// operation at its defaults contributes no code, no uniform and no
|
||||
// dispatch. An unedited photograph must not pay for a sharpener it is
|
||||
// not using.
|
||||
let ops = with_blur(0.0);
|
||||
let composed = compose_detail(
|
||||
&ops,
|
||||
RenderScale::full((512, 512)),
|
||||
dr_types::ColourSpace::Srgb,
|
||||
);
|
||||
assert!(composed.is_empty());
|
||||
assert_eq!(fused(&ops).output_mode, OutputMode::Encoded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_separable_blur_becomes_two_passes_and_only_the_last_encodes() {
|
||||
// The multi-pass case, which is the one the ping-pong exists for. The
|
||||
// first pass writes a linear intermediate and the second writes the
|
||||
// display texture — so the output transform happens exactly once, at
|
||||
// the end, wherever the end happens to be.
|
||||
let ops = with_blur(0.05);
|
||||
let composed = compose_detail(
|
||||
&ops,
|
||||
RenderScale::full((512, 512)),
|
||||
dr_types::ColourSpace::Srgb,
|
||||
);
|
||||
assert_eq!(composed.len(), 2);
|
||||
|
||||
let first = &composed.passes[0];
|
||||
let last = &composed.passes[1];
|
||||
assert_eq!(first.label, "detail_probe/horizontal");
|
||||
assert_eq!(last.label, "detail_probe/vertical");
|
||||
|
||||
assert!(!first.writes_output);
|
||||
assert!(first.source.contains("texture_storage_2d<rgba16float"));
|
||||
assert!(!first.source.contains("fn encode_output"));
|
||||
|
||||
assert!(last.writes_output);
|
||||
assert!(last.source.contains("texture_storage_2d<rgba8unorm"));
|
||||
assert!(last.source.contains("fn encode_output"));
|
||||
|
||||
// Two passes of one operation are two shaders, so they must not share
|
||||
// a pipeline-cache entry — the classic way a second pass silently runs
|
||||
// the first one's code.
|
||||
assert_ne!(first.structure_hash, last.structure_hash);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pass_addresses_its_uniforms_without_knowing_the_block() {
|
||||
// The same contract the fused composer offers: a body writes `radius`
|
||||
// and the composer rewrites it to a prefixed struct field, so two
|
||||
// operations may both call a uniform `radius` and neither has to know.
|
||||
let ops = with_blur(0.05);
|
||||
let composed = compose_detail(
|
||||
&ops,
|
||||
RenderScale::full((512, 512)),
|
||||
dr_types::ColourSpace::Srgb,
|
||||
);
|
||||
let src = &composed.passes[0].source;
|
||||
assert!(src.contains("detail_probe_0_radius: f32,"));
|
||||
assert!(src.contains("let r = i32(u.detail_probe_0_radius);"));
|
||||
// And the second pass carries its own index, so its uniforms cannot be
|
||||
// uploaded into the first pass's slots.
|
||||
assert!(composed.passes[1]
|
||||
.source
|
||||
.contains("detail_probe_1_radius: f32,"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_pass_declares_a_uniform_block_the_gpu_will_accept() {
|
||||
// A uniform struct whose size is not a multiple of 16 is rejected
|
||||
// outright by the WGSL uniform address space rules, and the failure
|
||||
// arrives as a shader compilation error against generated source.
|
||||
let ops = with_blur(0.05);
|
||||
for pass in compose_detail(
|
||||
&ops,
|
||||
RenderScale::full((512, 512)),
|
||||
dr_types::ColourSpace::Srgb,
|
||||
)
|
||||
.passes
|
||||
{
|
||||
assert_eq!(pass.uniforms.len() % 4, 0, "{}", pass.label);
|
||||
assert!(pass.uniforms.iter().all(|v| v.is_finite()));
|
||||
// The base block is first and fixed, so a pass never addresses a
|
||||
// slot by number and the render size is always in the same place.
|
||||
assert_eq!(pass.uniforms[0], 512.0);
|
||||
assert_eq!(pass.uniforms[1], 512.0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_declared_radius_is_the_halo_a_tile_would_need() {
|
||||
// ARCH §5.3 schedules tiles, and a tile cannot be computed without
|
||||
// knowing how far outside itself the pass reads. Nothing can infer it
|
||||
// from the WGSL — the offsets are computed from uniforms at runtime —
|
||||
// so the operation states it, and this is the assertion that it states
|
||||
// the truth rather than zero.
|
||||
let ops = with_blur(0.05);
|
||||
let scale = RenderScale::full((400, 400));
|
||||
let composed = compose_detail(&ops, scale, dr_types::ColourSpace::Srgb);
|
||||
let expected = BoxBlur::with_radius(0.05).kernel(scale);
|
||||
assert_eq!(expected, 20, "5% of a 400px edge");
|
||||
assert_eq!(composed.radius(), expected);
|
||||
assert!(composed.passes.iter().all(|p| p.radius == expected));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_normalised_radius_is_the_same_effect_at_every_resolution() {
|
||||
// FR-DSP-1's hard part, at the level this crate can test it: the same
|
||||
// edit composed at two sizes produces kernels in the same *proportion*
|
||||
// to the frame. `dr-gpu`'s `proxy_and_export_agree` checks the pixels
|
||||
// that fall out of it.
|
||||
let ops = with_blur(0.04);
|
||||
let sizes = [(200u32, 200u32), (800, 800), (2400, 2400)];
|
||||
let fractions: Vec<f32> = sizes
|
||||
.iter()
|
||||
.map(|&(w, h)| {
|
||||
let scale = RenderScale::full((w, h));
|
||||
let composed = compose_detail(&ops, scale, dr_types::ColourSpace::Srgb);
|
||||
composed.radius() as f32 / w.min(h) as f32
|
||||
})
|
||||
.collect();
|
||||
for f in &fractions {
|
||||
assert!(
|
||||
(f - 0.04).abs() < 0.005,
|
||||
"the kernel drifted from the declared fraction: {fractions:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_edit_with_no_detail_operation_composes_no_passes() {
|
||||
// The property that keeps the cost of this stage at zero for the
|
||||
// overwhelmingly common edit: no sharpening means no chain, which
|
||||
// means `dr-gpu` runs the single fused dispatch it always did.
|
||||
let ops = crate::ops::chain();
|
||||
let composed = compose_detail(
|
||||
&ops,
|
||||
RenderScale::full((64, 64)),
|
||||
dr_types::ColourSpace::Srgb,
|
||||
);
|
||||
assert!(composed.is_empty());
|
||||
assert_eq!(composed.radius(), 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
//! A separable box blur, for testing the detail stage. **Not a develop
|
||||
//! operation.**
|
||||
//!
|
||||
//! # Why an abstraction gets a fake consumer
|
||||
//!
|
||||
//! The detail stage was written before any of the operations it exists for —
|
||||
//! sharpening, noise reduction, clarity, spot removal are each their own piece
|
||||
//! of work — and an abstraction with no consumer is a guess. Nothing would
|
||||
//! have proved that the WGSL it generates compiles, that the ping-pong hands
|
||||
//! pass two what pass one wrote, that the last pass really does encode, or
|
||||
//! that a radius stated in one unit survives the trip from a proxy to an
|
||||
//! export.
|
||||
//!
|
||||
//! So the stage has exactly one consumer, and it lives here, behind the
|
||||
//! `detail-probe` feature. It is deliberately *not* declared in `ops/`: it has
|
||||
//! no `order:`, it is not in [`crate::ops::chain`], it never reaches
|
||||
//! [`crate::EditGraph::capabilities`], and so it cannot appear in the develop
|
||||
//! panel or in a sidecar. A shipping build does not contain it.
|
||||
//!
|
||||
//! # Why a box blur specifically
|
||||
//!
|
||||
//! Because its answer is known in closed form. A box blur of radius *r* over a
|
||||
//! step edge produces a ramp exactly `2r + 1` pixels wide with a known value
|
||||
//! at every step, so a test can assert *pixels*, not "something changed". A
|
||||
//! Gaussian would need a tolerance chosen to hide whatever the implementation
|
||||
//! actually did.
|
||||
//!
|
||||
//! And because it is **separable**, which is the property the two-pass case
|
||||
//! was built for: a horizontal pass then a vertical one is mathematically a 2D
|
||||
//! box average, so if the ping-pong is wired backwards or a pass reads its own
|
||||
//! output the result is visibly not a box blur rather than subtly wrong.
|
||||
|
||||
use crate::descriptor::{
|
||||
Attribute, LocalizedKey, OpDescriptor, OpId, ParamDescriptor, ParamId, ParamKind, Scale, Unit,
|
||||
};
|
||||
use crate::detail::{DetailPass, DetailStage, RenderScale};
|
||||
use crate::operation::{Affects, Operation, Uniform};
|
||||
|
||||
static DESCRIPTOR: OpDescriptor = OpDescriptor {
|
||||
id: OpId("detail_probe"),
|
||||
label: LocalizedKey("op.detail_probe"),
|
||||
params: &[ParamDescriptor {
|
||||
id: ParamId("radius"),
|
||||
label: LocalizedKey("param.detail_probe.radius"),
|
||||
// A fraction of the frame's shorter edge, which is the unit
|
||||
// `RenderScale::frame_fraction` converts and the unit a mask feather
|
||||
// is already stored in. Stating it in pixels is the mistake this
|
||||
// whole stage is arranged to make impossible.
|
||||
kind: ParamKind::Scalar {
|
||||
min: 0.0,
|
||||
max: 0.25,
|
||||
scale: Scale::Linear,
|
||||
unit: Unit::None,
|
||||
precision: 4,
|
||||
},
|
||||
default: 0.0,
|
||||
facet: None,
|
||||
}],
|
||||
attributes: &[Attribute::Detail],
|
||||
};
|
||||
|
||||
/// A separable box blur whose radius is a fraction of the frame's shorter edge.
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub struct BoxBlur {
|
||||
radius: f32,
|
||||
}
|
||||
|
||||
impl BoxBlur {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Set the radius directly, in fractions of the shorter edge.
|
||||
pub fn with_radius(radius: f32) -> Self {
|
||||
Self { radius }
|
||||
}
|
||||
|
||||
/// The kernel radius this blur would use at `scale`, in render pixels.
|
||||
///
|
||||
/// Exposed so a test can state the expected ramp width without repeating
|
||||
/// the rounding rule — a test that recomputed it would agree with a bug.
|
||||
pub fn kernel(&self, scale: RenderScale) -> u32 {
|
||||
scale.frame_fraction(self.radius).round().max(0.0) as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl Operation for BoxBlur {
|
||||
fn descriptor(&self) -> &'static OpDescriptor {
|
||||
&DESCRIPTOR
|
||||
}
|
||||
|
||||
fn set_param(&mut self, _id: ParamId, value: f32) {
|
||||
self.radius = value;
|
||||
}
|
||||
|
||||
fn param(&self, _id: ParamId) -> f32 {
|
||||
self.radius
|
||||
}
|
||||
|
||||
fn is_active(&self) -> bool {
|
||||
self.radius > 0.0
|
||||
}
|
||||
|
||||
/// Never called. A detail operation contributes no fused fragment, and
|
||||
/// [`crate::operation::compose_full`] filters it out before asking.
|
||||
fn wgsl_body(&self) -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
fn uniforms(&self) -> Vec<Uniform> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
fn affects(&self) -> Affects {
|
||||
Affects::Detail
|
||||
}
|
||||
|
||||
fn detail(&self) -> Option<&dyn DetailStage> {
|
||||
Some(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl DetailStage for BoxBlur {
|
||||
fn passes(&self, scale: RenderScale) -> Vec<DetailPass> {
|
||||
let r = self.kernel(scale);
|
||||
// A radius that rounded to nothing is not "blur by zero" — it is an
|
||||
// effect this render is too small to show. Emitting a pass that
|
||||
// averages one pixel would burn a dispatch to copy the image.
|
||||
if r == 0 {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
// Two passes, one per axis. The horizontal one reads the fused pass's
|
||||
// output and the vertical one reads the horizontal one's, which is the
|
||||
// whole point: if the ping-pong were wired to hand the second pass the
|
||||
// original again, the result would be a horizontal smear rather than a
|
||||
// box, and the test asserting a symmetric ramp would say so.
|
||||
["x", "y"]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(axis, _)| DetailPass {
|
||||
label: if axis == 0 { "horizontal" } else { "vertical" },
|
||||
radius: r,
|
||||
uniforms: vec![
|
||||
Uniform {
|
||||
name: "radius",
|
||||
value: r as f32,
|
||||
},
|
||||
Uniform {
|
||||
name: "step_x",
|
||||
value: if axis == 0 { 1.0 } else { 0.0 },
|
||||
},
|
||||
Uniform {
|
||||
name: "step_y",
|
||||
value: if axis == 0 { 0.0 } else { 1.0 },
|
||||
},
|
||||
],
|
||||
wgsl: "// One axis of a separable box average.
|
||||
//
|
||||
// `tap` clamps at the border, so a kernel hanging off the edge averages the
|
||||
// edge pixel repeatedly rather than averaging in black — which keeps a
|
||||
// constant image constant, the cheapest property to check and the first one
|
||||
// a broken border rule breaks.
|
||||
let r = i32(radius);
|
||||
let step = vec2<i32>(i32(step_x), i32(step_y));
|
||||
var sum = vec3<f32>(0.0);
|
||||
for (var i = -r; i <= r; i = i + 1) {
|
||||
sum = sum + tap(coord, step * i);
|
||||
}
|
||||
c = sum / f32(2 * r + 1);"
|
||||
.to_string(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
@@ -118,6 +118,28 @@ impl EditGraph {
|
||||
}
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3
|
||||
/// The default chain with the detail stage's test consumer appended.
|
||||
///
|
||||
/// **Not a shipping path.** `detail_probe` is a separable box blur that
|
||||
/// exists so the neighbourhood stage has something to run (see
|
||||
/// [`crate::detail::probe`]); it is not declared in `ops/`, has no place
|
||||
/// in the pipeline order, and is compiled only for tests and behind the
|
||||
/// `detail-probe` feature.
|
||||
///
|
||||
/// It is a constructor rather than a fixture inside one test module
|
||||
/// because `dr-gpu` needs the same graph: proving the stage works means
|
||||
/// dispatching it, and dispatching it means composing both halves of the
|
||||
/// shader from one graph exactly as the interface will.
|
||||
#[cfg(any(test, feature = "detail-probe"))]
|
||||
pub fn with_detail_probe() -> Self {
|
||||
let mut graph = Self::default_chain();
|
||||
graph
|
||||
.ops
|
||||
.push(Box::new(crate::detail::probe::BoxBlur::new()));
|
||||
graph
|
||||
}
|
||||
|
||||
/// The local adjustment stack.
|
||||
pub fn masks(&self) -> &MaskStack {
|
||||
&self.masks
|
||||
@@ -342,6 +364,130 @@ impl EditGraph {
|
||||
pub fn compose_for(&self, output: dr_types::ColourSpace) -> ComposedShader {
|
||||
compose_full(&self.ops, &self.framing, output, &self.masks)
|
||||
}
|
||||
|
||||
/// TRACES: FR-DSP-1
|
||||
/// How this render relates to the file it stands for.
|
||||
///
|
||||
/// `source` is the demosaiced image's size and `render` the size being
|
||||
/// drawn now. The result describes *the region on screen*, with the crop
|
||||
/// and the zoom already folded in: cropping to half the frame while the
|
||||
/// viewport stays the same size genuinely does show twice the detail, and
|
||||
/// zooming to 1:1 genuinely does make the preview exact. Both fall out of
|
||||
/// the arithmetic rather than needing a special case.
|
||||
///
|
||||
/// Only the detail stage needs this. Every point operation is scale-free
|
||||
/// — a multiply is a multiply at any resolution — which is why nothing in
|
||||
/// the pipeline had to know its own size until a kernel arrived.
|
||||
pub fn render_scale(&self, source: (u32, u32), render: (u32, u32)) -> crate::detail::RenderScale {
|
||||
let (fw, fh) = self.framing.output_size(source.0, source.1);
|
||||
let view = self.framing.view();
|
||||
// The *viewed* part of the framed image, at source resolution. Zoom
|
||||
// shrinks the view rect while the render target keeps its size, so
|
||||
// this is what shrinks and the ratio is what climbs.
|
||||
let full = (
|
||||
((fw as f32 * view.width).round() as u32).max(1),
|
||||
((fh as f32 * view.height).round() as u32).max(1),
|
||||
);
|
||||
crate::detail::RenderScale::new(render, full)
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3 | FR-DSP-1
|
||||
/// Generate the detail stage for this edit at one resolution, to sRGB.
|
||||
///
|
||||
/// Empty for every edit with no active neighbourhood operation, which is
|
||||
/// almost all of them — and in that case [`Self::compose`] emits the
|
||||
/// single encoded dispatch it always has.
|
||||
pub fn compose_detail(&self, scale: crate::detail::RenderScale) -> crate::detail::ComposedDetail {
|
||||
self.compose_detail_for(scale, dr_types::ColourSpace::Srgb)
|
||||
}
|
||||
|
||||
/// TRACES: FR-EXP-2
|
||||
/// The detail stage, encoded into a chosen output space.
|
||||
///
|
||||
/// The space belongs here as well as on [`Self::compose_for`] because when
|
||||
/// a detail stage exists it is the *last* pass that performs the output
|
||||
/// transform — the fused pass stops at linear working values. Composing
|
||||
/// the two halves for different spaces would encode the edit twice, or
|
||||
/// not at all.
|
||||
pub fn compose_detail_for(
|
||||
&self,
|
||||
scale: crate::detail::RenderScale,
|
||||
output: dr_types::ColourSpace,
|
||||
) -> crate::detail::ComposedDetail {
|
||||
crate::detail::compose_detail(&self.ops, scale, output)
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3d
|
||||
/// The per-stage cache keys for the current edit.
|
||||
///
|
||||
/// See [`crate::Invalidation`] for what the keys mean and what may be
|
||||
/// cached against them. In short: geometry covers the framing, colour
|
||||
/// covers every fused operation and every mask layer, and detail covers
|
||||
/// the neighbourhood operations — so moving one slider moves exactly one
|
||||
/// key, and a consumer can tell which stages it has to redo.
|
||||
pub fn invalidation(&self) -> crate::Invalidation {
|
||||
use crate::operation::{hash_bytes, hash_op, mix, Affects, FNV_OFFSET};
|
||||
|
||||
// Geometry: the framing. Its own structure key covers the shape of the
|
||||
// coordinate map; the parameters cover the magnitudes, which the
|
||||
// structure key deliberately omits because they do not recompile a
|
||||
// shader. Both matter to a cached *result*, so both are here.
|
||||
let mut geometry = mix(FNV_OFFSET, self.framing.structure_key());
|
||||
for p in self.framing.descriptor().params {
|
||||
geometry = hash_bytes(geometry, p.id.0.as_bytes());
|
||||
geometry = mix(
|
||||
geometry,
|
||||
u64::from(crate::operation::canonical_bits(self.framing.param(p.id))),
|
||||
);
|
||||
}
|
||||
// The view rect is not a parameter and not in the structure key — it
|
||||
// is not an edit (see `Framing::view`). It is still an input to every
|
||||
// rendered pixel, so a cache that ignored it would show the wrong part
|
||||
// of the photograph after a scroll.
|
||||
let view = self.framing.view();
|
||||
for v in [view.x, view.y, view.width, view.height] {
|
||||
geometry = mix(geometry, u64::from(crate::operation::canonical_bits(v)));
|
||||
}
|
||||
|
||||
let mut colour = FNV_OFFSET;
|
||||
let mut detail = FNV_OFFSET;
|
||||
for op in &self.ops {
|
||||
let target = if op.affects() == Affects::Detail {
|
||||
&mut detail
|
||||
} else {
|
||||
&mut colour
|
||||
};
|
||||
*target = hash_op(*target, op.as_ref());
|
||||
}
|
||||
|
||||
// The mask layers belong to the colour stage: their chains are fused
|
||||
// into the same dispatch, and a layer's *shape* decides which pixels
|
||||
// that dispatch treats differently. Both halves are folded in.
|
||||
for layer in self.masks.layers() {
|
||||
colour = hash_bytes(colour, layer.id.as_bytes());
|
||||
// The source through its `Debug`, deliberately. A gradient's
|
||||
// centre, a region's id list and a subject's signature are all
|
||||
// part of where the layer applies, and matching on the variants
|
||||
// here would be a second copy of `MaskSource`'s shape that falls
|
||||
// out of step the first time a variant gains a field — silently,
|
||||
// and showing as a mask that stops updating. `Debug` cannot fall
|
||||
// out of step, because it is derived from the definition itself.
|
||||
colour = hash_bytes(colour, format!("{:?}", layer.source).as_bytes());
|
||||
colour = mix(colour, u64::from(layer.enabled));
|
||||
colour = mix(colour, u64::from(layer.invert));
|
||||
colour = hash_bytes(colour, layer.falloff.name().as_bytes());
|
||||
for v in [layer.opacity, layer.feather, layer.morph_radius] {
|
||||
colour = mix(colour, u64::from(crate::operation::canonical_bits(v)));
|
||||
}
|
||||
for (op_id, param_id, value) in layer.params() {
|
||||
colour = hash_bytes(colour, op_id.as_bytes());
|
||||
colour = hash_bytes(colour, param_id.as_bytes());
|
||||
colour = mix(colour, u64::from(crate::operation::canonical_bits(value)));
|
||||
}
|
||||
}
|
||||
|
||||
crate::Invalidation::new(geometry, colour, detail)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for EditGraph {
|
||||
@@ -645,4 +791,220 @@ mod tests {
|
||||
);
|
||||
assert_ne!(before, g.compose().structure_hash);
|
||||
}
|
||||
|
||||
// ---- invalidation scoping (FR-DEV-3d) --------------------------------
|
||||
|
||||
use crate::descriptor::OpId;
|
||||
use crate::operation::Affects;
|
||||
|
||||
const PROBE: OpId = OpId("detail_probe");
|
||||
const PROBE_RADIUS: ParamId = ParamId("radius");
|
||||
|
||||
#[test]
|
||||
fn moving_a_detail_parameter_leaves_every_earlier_stage_alone() {
|
||||
// FR-DEV-3d's headline, and the thing `Affects::Detail` was added to
|
||||
// make true: dragging a sharpening slider must not re-run the
|
||||
// demosaic, the framing, or the fused colour pass. The demosaic is not
|
||||
// a key here at all — no parameter in this graph can reach it — and
|
||||
// the other two must come out unchanged.
|
||||
let mut g = EditGraph::with_detail_probe();
|
||||
let before = g.invalidation();
|
||||
|
||||
g.set_param(PROBE, PROBE_RADIUS, 0.05);
|
||||
let after = g.invalidation();
|
||||
|
||||
assert_ne!(
|
||||
before.of(Affects::Detail),
|
||||
after.of(Affects::Detail),
|
||||
"the detail stage's own key must move"
|
||||
);
|
||||
assert_eq!(
|
||||
before.through(Affects::Colour),
|
||||
after.through(Affects::Colour),
|
||||
"the fused colour pass's result is still valid, so its cached \
|
||||
linear intermediate must be reusable"
|
||||
);
|
||||
assert_eq!(
|
||||
before.through(Affects::Geometry),
|
||||
after.through(Affects::Geometry)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moving_a_colour_parameter_leaves_geometry_alone_and_redoes_detail() {
|
||||
// The other direction, and the half that is easy to get wrong by
|
||||
// wishing. Exposure does not touch the framing — FR-DEV-3d says so in
|
||||
// as many words. It *does* invalidate the detail stage's output,
|
||||
// because the detail stage reads what the colour pass wrote, and
|
||||
// pretending otherwise would show a sharpened version of the previous
|
||||
// exposure. The stage's own parameters are still untouched, which is
|
||||
// what `of` reports and `through` does not.
|
||||
let mut g = EditGraph::with_detail_probe();
|
||||
g.set_param(PROBE, PROBE_RADIUS, 0.05);
|
||||
let before = g.invalidation();
|
||||
|
||||
g.set_param(exposure::ID, exposure::EXPOSURE, 1.0);
|
||||
let after = g.invalidation();
|
||||
|
||||
assert_eq!(
|
||||
before.through(Affects::Geometry),
|
||||
after.through(Affects::Geometry),
|
||||
"adjusting exposure shall not re-tile geometry (FR-DEV-3d)"
|
||||
);
|
||||
assert_ne!(before.of(Affects::Colour), after.of(Affects::Colour));
|
||||
assert_eq!(
|
||||
before.of(Affects::Detail),
|
||||
after.of(Affects::Detail),
|
||||
"the sharpening settings did not change"
|
||||
);
|
||||
assert_ne!(
|
||||
before.through(Affects::Detail),
|
||||
after.through(Affects::Detail),
|
||||
"but its input did, so its cached output is stale"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cropping_invalidates_everything_downstream_of_it() {
|
||||
// Geometry is upstream of both other stages: it decides which source
|
||||
// pixel every colour is read from, and — because the detail stage runs
|
||||
// at render resolution — how many render pixels a kernel spans.
|
||||
let mut g = EditGraph::with_detail_probe();
|
||||
g.set_param(PROBE, PROBE_RADIUS, 0.05);
|
||||
let before = g.invalidation();
|
||||
|
||||
g.set_crop(CropRect {
|
||||
x: 0.1,
|
||||
y: 0.1,
|
||||
width: 0.5,
|
||||
height: 0.5,
|
||||
});
|
||||
let after = g.invalidation();
|
||||
|
||||
assert_ne!(before.of(Affects::Geometry), after.of(Affects::Geometry));
|
||||
assert_ne!(
|
||||
before.through(Affects::Colour),
|
||||
after.through(Affects::Colour)
|
||||
);
|
||||
assert_ne!(
|
||||
before.through(Affects::Detail),
|
||||
after.through(Affects::Detail)
|
||||
);
|
||||
// Scoped, though: neither later stage's *own* settings moved.
|
||||
assert_eq!(before.of(Affects::Colour), after.of(Affects::Colour));
|
||||
assert_eq!(before.of(Affects::Detail), after.of(Affects::Detail));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scrolling_the_view_invalidates_the_render_without_being_an_edit() {
|
||||
// The view rect is not an edit — it is excluded from the sidecar, the
|
||||
// structure hash and `is_active` — but it absolutely is an input to
|
||||
// every pixel. A key that ignored it would leave the previous part of
|
||||
// the photograph on screen after a pan, which looks like a repaint bug
|
||||
// and is a cache bug.
|
||||
let mut g = EditGraph::default_chain();
|
||||
let before = g.invalidation();
|
||||
g.framing_mut().set_view(CropRect {
|
||||
x: 0.25,
|
||||
y: 0.25,
|
||||
width: 0.5,
|
||||
height: 0.5,
|
||||
});
|
||||
assert_ne!(
|
||||
before.of(Affects::Geometry),
|
||||
g.invalidation().of(Affects::Geometry)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn returning_a_slider_to_where_it_was_returns_the_key() {
|
||||
// A cache key that drifted with the *path* rather than the state would
|
||||
// never hit after an undo, which is the moment it is most wanted.
|
||||
let mut g = EditGraph::with_detail_probe();
|
||||
let origin = g.invalidation();
|
||||
g.set_param(exposure::ID, exposure::EXPOSURE, 1.5);
|
||||
g.set_param(PROBE, PROBE_RADIUS, 0.05);
|
||||
assert_ne!(origin, g.invalidation());
|
||||
|
||||
g.set_param(exposure::ID, exposure::EXPOSURE, 0.0);
|
||||
g.set_param(PROBE, PROBE_RADIUS, 0.0);
|
||||
assert_eq!(origin, g.invalidation(), "the state is what is hashed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_local_adjustment_belongs_to_the_colour_stage() {
|
||||
// A mask layer's chain is fused into the same dispatch as the global
|
||||
// one, so changing it is a colour change and nothing more. Its
|
||||
// *shape* counts too: which pixels the dispatch treats differently is
|
||||
// as much a part of the result as by how much.
|
||||
use crate::mask::{MaskLayer, MaskSource};
|
||||
let mut g = EditGraph::with_detail_probe();
|
||||
let before = g.invalidation();
|
||||
|
||||
g.masks_mut().push(MaskLayer::new(
|
||||
"l1",
|
||||
MaskSource::Linear {
|
||||
centre: (0.5, 0.5),
|
||||
angle: 0.0,
|
||||
width: 0.2,
|
||||
},
|
||||
));
|
||||
let with_layer = g.invalidation();
|
||||
assert_ne!(before.of(Affects::Colour), with_layer.of(Affects::Colour));
|
||||
assert_eq!(
|
||||
before.of(Affects::Geometry),
|
||||
with_layer.of(Affects::Geometry)
|
||||
);
|
||||
assert_eq!(before.of(Affects::Detail), with_layer.of(Affects::Detail));
|
||||
|
||||
// Moving the gradient is a different mask, so a different result.
|
||||
if let Some(layer) = g.masks_mut().get_mut("l1") {
|
||||
layer.source = MaskSource::Linear {
|
||||
centre: (0.2, 0.7),
|
||||
angle: 0.4,
|
||||
width: 0.2,
|
||||
};
|
||||
}
|
||||
assert_ne!(
|
||||
with_layer.of(Affects::Colour),
|
||||
g.invalidation().of(Affects::Colour)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_render_scale_folds_in_the_crop_and_the_zoom() {
|
||||
// What a detail operation is handed, and the reason it does not need
|
||||
// to know that a crop or a zoom happened: both arrive already folded
|
||||
// into one ratio.
|
||||
let mut g = EditGraph::default_chain();
|
||||
let source = (6000, 4000);
|
||||
|
||||
// Fit: a 1500px panel over a 6000px frame is a quarter scale.
|
||||
let fit = g.render_scale(source, (1500, 1000));
|
||||
assert!((fit.ratio() - 0.25).abs() < 1e-3);
|
||||
|
||||
// Zoomed to 1:1 — the view rect shrinks to what the panel can hold,
|
||||
// the render target keeps its size, and the preview becomes exact.
|
||||
g.framing_mut().set_view(CropRect {
|
||||
x: 0.25,
|
||||
y: 0.25,
|
||||
width: 0.25,
|
||||
height: 0.25,
|
||||
});
|
||||
let one_to_one = g.render_scale(source, (1500, 1000));
|
||||
assert!((one_to_one.ratio() - 1.0).abs() < 1e-3);
|
||||
assert!(one_to_one.resolves(1.0));
|
||||
|
||||
// A crop shows fewer source pixels in the same panel, which is more
|
||||
// render pixels each — a sharpening radius genuinely does grow.
|
||||
let mut cropped = EditGraph::default_chain();
|
||||
cropped.set_crop(CropRect {
|
||||
x: 0.25,
|
||||
y: 0.25,
|
||||
width: 0.5,
|
||||
height: 0.5,
|
||||
});
|
||||
let after = cropped.render_scale(source, (1500, 1000));
|
||||
assert!(after.ratio() > fit.ratio());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
//! data neither would be physically meaningful (ARCH §5.2).
|
||||
|
||||
pub mod descriptor;
|
||||
pub mod detail;
|
||||
pub mod framing;
|
||||
pub mod graph;
|
||||
pub mod history;
|
||||
@@ -46,13 +47,16 @@ pub use descriptor::{
|
||||
Attribute, Facet, LocalizedKey, OpDescriptor, OpId, ParamDescriptor, ParamId, ParamKind, Presentation,
|
||||
Scale, Unit, WidgetDemand, WidgetKind,
|
||||
};
|
||||
pub use detail::{
|
||||
compose_detail, ComposedDetail, ComposedDetailPass, DetailPass, DetailStage, RenderScale,
|
||||
};
|
||||
pub use framing::{CropRect, Framing};
|
||||
pub use graph::{EditGraph, OpCapability, ParamCapability};
|
||||
pub use history::{Edit, History};
|
||||
pub use lens::{compose_warps, ComposedWarp, Warp};
|
||||
pub use operation::{
|
||||
compose, compose_with_framing, Affects, ComposedShader, Helper, Operation, Uniform,
|
||||
RESERVED_UNIFORM_FIELDS,
|
||||
compose, compose_with_framing, Affects, ComposedShader, Helper, Invalidation, Operation,
|
||||
OutputMode, Uniform, RESERVED_UNIFORM_FIELDS,
|
||||
};
|
||||
pub use preset::{Preset, Scope};
|
||||
pub use sidecar::{Sidecar, Version};
|
||||
|
||||
@@ -463,8 +463,22 @@ impl MaskLayer {
|
||||
self.enabled && self.opacity > 0.0 && self.active_ops().next().is_some()
|
||||
}
|
||||
|
||||
/// The operations in this layer's chain that reach the shader.
|
||||
///
|
||||
/// Neighbourhood operations are excluded, and not as an oversight. A
|
||||
/// layer's chain is *fused into the point-operation pass* and multiplied
|
||||
/// by the mask afterwards; the detail stage runs once, over the whole
|
||||
/// frame, after that pass has finished (see [`crate::detail`]). There is
|
||||
/// nowhere in that arrangement for a sharpening confined to one mask to
|
||||
/// happen, so a detail operation in a layer would contribute an empty
|
||||
/// block, count towards [`Self::is_active`], and cost a mask rasterisation
|
||||
/// to change nothing. Dropping it here means the layer reports honestly
|
||||
/// that it has no adjustment rather than appearing to have one.
|
||||
pub fn active_ops(&self) -> impl Iterator<Item = &dyn Operation> {
|
||||
self.ops.iter().map(|o| o.as_ref()).filter(|o| o.is_active())
|
||||
self.ops
|
||||
.iter()
|
||||
.map(|o| o.as_ref())
|
||||
.filter(|o| o.is_active() && o.detail().is_none())
|
||||
}
|
||||
|
||||
/// Whether this layer's region ids belong to a different segmentation.
|
||||
|
||||
@@ -28,19 +28,182 @@ use crate::descriptor::{OpDescriptor, ParamId, Presentation};
|
||||
use crate::framing::{Framing, FRAMING_UNIFORM_FIELDS};
|
||||
use crate::mask::MaskStack;
|
||||
|
||||
/// TRACES: FR-DEV-3d
|
||||
/// What an operation's parameters affect, for cache invalidation scoping.
|
||||
///
|
||||
/// Adjusting exposure must not invalidate the demosaic result; this is what
|
||||
/// lets the tile cache reuse everything up to the first changed stage
|
||||
/// (ARCH §5.3).
|
||||
///
|
||||
/// **The ordering is the pipeline order**, which is why this derives `Ord`
|
||||
/// rather than merely `Eq`: geometry decides which source pixel a colour comes
|
||||
/// from, the fused colour pass transforms it, and the detail stage reads the
|
||||
/// neighbourhood the colour pass produced. A change at one stage invalidates
|
||||
/// that stage and every later one, and nothing earlier — see [`Invalidation`],
|
||||
/// which is where that rule is actually written down and tested.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum Affects {
|
||||
/// Per-pixel colour only. Everything in this milestone.
|
||||
Colour,
|
||||
/// Pixel positions — crop, rotate. Invalidates geometry-dependent caches.
|
||||
/// Pixel positions — crop, rotate, straighten. The framing prologue, which
|
||||
/// also decides the resolution everything downstream runs at.
|
||||
Geometry,
|
||||
/// Per-pixel colour. Every operation fused into the single adjust
|
||||
/// dispatch, and every mask layer's chain.
|
||||
Colour,
|
||||
/// TRACES: FR-DEV-3d
|
||||
/// A pixel's *neighbourhood* — sharpening, noise reduction, clarity,
|
||||
/// texture, dehaze, spot removal.
|
||||
///
|
||||
/// The seam `docs/requirements.md` §3.3 designed and nothing cut until
|
||||
/// [`crate::detail`] existed. It is a separate variant rather than a flavour
|
||||
/// of `Colour` because it is a separate *dispatch*: a fragment in the fused
|
||||
/// pass is handed a colour and has no way back to a coordinate, so a
|
||||
/// kernel cannot be expressed there at any price.
|
||||
///
|
||||
/// What the distinction buys, concretely: the fused pass's result is held
|
||||
/// in a linear intermediate, so dragging a sharpening slider re-runs the
|
||||
/// detail dispatches and **not** the colour pass — which is exactly the
|
||||
/// reuse FR-DEV-3d asks for, and it is asserted in `dr-gpu`'s
|
||||
/// `detail_stage` tests rather than merely hoped for.
|
||||
Detail,
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3d
|
||||
/// One cache key per pipeline stage, derived from the edit.
|
||||
///
|
||||
/// # The rule
|
||||
///
|
||||
/// A cached result for stage *S* stays valid while *S*'s own key and the keys
|
||||
/// of every stage **before** it are unchanged. [`Self::of`] is the first half;
|
||||
/// [`Self::through`] folds in the second and is what a cache should actually
|
||||
/// store.
|
||||
///
|
||||
/// That reads as pedantry until it is applied, at which point it settles the
|
||||
/// two questions FR-DEV-3d asks:
|
||||
///
|
||||
/// - **Changing a detail parameter must not re-run demosaic**, or the framing,
|
||||
/// or the fused colour pass. It does not: `of(Detail)` moves and
|
||||
/// `through(Colour)` does not, so the linear intermediate the colour pass
|
||||
/// wrote is still good and only the detail dispatches run again.
|
||||
///
|
||||
/// - **Changing exposure must not re-run anything upstream of colour.** It
|
||||
/// does not: `through(Geometry)` is untouched, so a tile cache keyed on it
|
||||
/// survives, and the demosaiced texture — which no key here mentions at all
|
||||
/// — is never in question.
|
||||
///
|
||||
/// It also settles what is *not* true, and the temptation is real: changing
|
||||
/// exposure **does** re-run the detail passes, because the detail stage reads
|
||||
/// what the colour pass wrote and that changed. There is no arrangement of
|
||||
/// keys that avoids it while keeping sharpening after the tone curve, and
|
||||
/// sharpening after the tone curve is the correct place (see
|
||||
/// [`crate::detail`]). Anyone who wants exposure to leave the detail stage
|
||||
/// alone is asking for detail to run *before* tone, which is a different
|
||||
/// pipeline and a worse picture.
|
||||
///
|
||||
/// # Why the demosaic is not in here
|
||||
///
|
||||
/// Because no parameter in this graph can change it. The demosaiced texture is
|
||||
/// a function of the file and the decode settings, both of which live outside
|
||||
/// the edit graph; a caller keying a cache on it mixes in whatever names the
|
||||
/// photograph — a `VersionId` — and these keys ride on top.
|
||||
///
|
||||
/// # Integer state only
|
||||
///
|
||||
/// Every value folded in here is a parameter: a slider position or a number
|
||||
/// from a sidecar, never a float that came back from the GPU. That is what
|
||||
/// ARCH §6.13 requires of a cache key, and it is why hashing the raw bit
|
||||
/// patterns is sound rather than reckless. Negative zero is canonicalised on
|
||||
/// the way in, because `-0.0 == 0.0` while their bit patterns differ, and a
|
||||
/// slider that arrived at zero from below would otherwise invalidate a cache
|
||||
/// that is perfectly valid.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Invalidation {
|
||||
geometry: u64,
|
||||
colour: u64,
|
||||
detail: u64,
|
||||
}
|
||||
|
||||
impl Invalidation {
|
||||
/// Build from the three per-stage hashes. [`crate::EditGraph::invalidation`]
|
||||
/// is what computes them; this is public so a caller with its own notion
|
||||
/// of a stage can construct one.
|
||||
pub fn new(geometry: u64, colour: u64, detail: u64) -> Self {
|
||||
Self {
|
||||
geometry,
|
||||
colour,
|
||||
detail,
|
||||
}
|
||||
}
|
||||
|
||||
/// The key for `stage`'s own parameters, ignoring everything upstream.
|
||||
///
|
||||
/// Useful for asserting that a change was correctly *scoped* — that moving
|
||||
/// a detail slider left the colour stage's parameters alone. Not a cache
|
||||
/// key: a stage whose own parameters are unchanged still has to re-run if
|
||||
/// its input changed, which is what [`Self::through`] is for.
|
||||
pub fn of(&self, stage: Affects) -> u64 {
|
||||
match stage {
|
||||
Affects::Geometry => self.geometry,
|
||||
Affects::Colour => self.colour,
|
||||
Affects::Detail => self.detail,
|
||||
}
|
||||
}
|
||||
|
||||
/// The key for the **output** of `stage` — this stage and everything
|
||||
/// upstream of it. What a cached texture should be keyed on.
|
||||
pub fn through(&self, stage: Affects) -> u64 {
|
||||
let mut h = FNV_OFFSET;
|
||||
h = mix(h, self.geometry);
|
||||
if stage >= Affects::Colour {
|
||||
h = mix(h, self.colour);
|
||||
}
|
||||
if stage >= Affects::Detail {
|
||||
h = mix(h, self.detail);
|
||||
}
|
||||
h
|
||||
}
|
||||
}
|
||||
|
||||
/// Fold one operation's identity and settings into a running hash.
|
||||
///
|
||||
/// Shared by the stage keys so that two stages cannot come to disagree about
|
||||
/// what "this operation's state" means — which would show as a cache that is
|
||||
/// occasionally, unreproducibly stale.
|
||||
pub(crate) fn hash_op(h: u64, op: &dyn Operation) -> u64 {
|
||||
let desc = op.descriptor();
|
||||
let mut h = hash_bytes(h, desc.id.0.as_bytes());
|
||||
for p in desc.params {
|
||||
h = hash_bytes(h, p.id.0.as_bytes());
|
||||
h = mix(h, u64::from(canonical_bits(op.param(p.id))));
|
||||
}
|
||||
h
|
||||
}
|
||||
|
||||
/// A parameter's bits, with negative zero folded onto zero.
|
||||
///
|
||||
/// `-0.0 == 0.0` as far as every operation is concerned — a slider that
|
||||
/// reached zero from below produces the same shader and the same picture — but
|
||||
/// the two have different bit patterns. Hashing them apart would invalidate a
|
||||
/// cache for a change that is not one.
|
||||
pub(crate) fn canonical_bits(v: f32) -> u32 {
|
||||
if v == 0.0 {
|
||||
0
|
||||
} else {
|
||||
v.to_bits()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn hash_bytes(mut h: u64, bytes: &[u8]) -> u64 {
|
||||
for byte in bytes {
|
||||
h ^= u64::from(*byte);
|
||||
h = h.wrapping_mul(0x100_0000_01b3);
|
||||
}
|
||||
h
|
||||
}
|
||||
|
||||
/// FNV-1a's offset basis. No dependency, and stable across runs and platforms,
|
||||
/// which a cache key requires.
|
||||
pub(crate) const FNV_OFFSET: u64 = 0xcbf2_9ce4_8422_2325;
|
||||
|
||||
/// A single scalar a fragment reads from the generated uniform block.
|
||||
///
|
||||
/// Operations declare uniforms by name and value; the composer assigns them
|
||||
@@ -85,6 +248,10 @@ pub trait Operation: Send + Sync {
|
||||
///
|
||||
/// The fragment runs inside its own block, so locals need no unique
|
||||
/// names.
|
||||
///
|
||||
/// Never called on an operation that declares a [`Self::detail`] stage —
|
||||
/// a neighbourhood operation is a dispatch of its own and contributes
|
||||
/// nothing to the fused shader, so it returns an empty string.
|
||||
fn wgsl_body(&self) -> String;
|
||||
|
||||
/// Uniform values this operation's fragment reads.
|
||||
@@ -95,6 +262,26 @@ pub trait Operation: Send + Sync {
|
||||
Affects::Colour
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3 | FR-DEV-8
|
||||
/// This operation's neighbourhood stage, if it has one.
|
||||
///
|
||||
/// `None` — the default, and true of every operation that is a function of
|
||||
/// one colour — means the operation is fused into the single adjust
|
||||
/// dispatch in the ordinary way.
|
||||
///
|
||||
/// `Some` means the opposite: the operation reads pixels it is not
|
||||
/// writing, cannot be a fragment in a fused shader, and runs as its own
|
||||
/// dispatch or dispatches after the colour pass. See [`crate::detail`] for
|
||||
/// where that sits and why, and for what a sharpening operation has to
|
||||
/// write. An operation returning `Some` must also return
|
||||
/// [`Affects::Detail`] from [`Self::affects`], which
|
||||
/// `detail_operations_agree_with_themselves` checks — the two saying
|
||||
/// different things would leave the operation in neither stage, silently
|
||||
/// doing nothing.
|
||||
fn detail(&self) -> Option<&dyn crate::detail::DetailStage> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Any WGSL helper functions the fragment calls.
|
||||
///
|
||||
/// Emitted once per *distinct* function name even if several operations
|
||||
@@ -128,6 +315,32 @@ pub struct Helper {
|
||||
pub source: &'static str,
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-2 | FR-DEV-3d
|
||||
/// What the fused pass writes, and therefore what has to be bound to it.
|
||||
///
|
||||
/// The fused shader ends one of two ways, and the difference is not cosmetic —
|
||||
/// it decides the storage texture's format, so a shader composed for one and
|
||||
/// dispatched against the other is a validation failure rather than a wrong
|
||||
/// picture.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum OutputMode {
|
||||
/// `rgba8unorm`, display-encoded in the composed output space. What the
|
||||
/// pass has always written, and still writes for the overwhelmingly common
|
||||
/// edit that has no detail stage: one dispatch, one read, one write.
|
||||
Encoded,
|
||||
/// `rgba16float`, linear sRGB, **unclipped**, scene-referred.
|
||||
///
|
||||
/// Emitted when the edit has an active neighbourhood operation. The detail
|
||||
/// passes read this, and the last of them performs the output transform,
|
||||
/// so the pipeline still quantises exactly once (FR-DEV-2) — it simply
|
||||
/// happens two dispatches later.
|
||||
///
|
||||
/// Unclipped matters: a recovered highlight is above 1.0 here, and
|
||||
/// clamping before a sharpener sees it would draw a hard edge at precisely
|
||||
/// the luminance a sharpener is most visible at.
|
||||
LinearWorking,
|
||||
}
|
||||
|
||||
/// The result of composing a set of operations into one shader.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ComposedShader {
|
||||
@@ -139,6 +352,8 @@ pub struct ComposedShader {
|
||||
/// not their values. Two edits differing only in slider positions share
|
||||
/// a compiled pipeline and differ only in the uniform upload.
|
||||
pub structure_hash: u64,
|
||||
/// What this shader writes. See [`OutputMode`].
|
||||
pub output_mode: OutputMode,
|
||||
}
|
||||
|
||||
/// Fields the generated uniform struct always carries, before op uniforms.
|
||||
@@ -211,12 +426,33 @@ pub fn compose_full(
|
||||
output: ColourSpace,
|
||||
masks: &MaskStack,
|
||||
) -> ComposedShader {
|
||||
// Active *point* operations. A neighbourhood operation is filtered out
|
||||
// here rather than asked for a fragment it cannot write: it reads pixels
|
||||
// it is not writing, so it belongs to the detail stage that runs after
|
||||
// this one (see `crate::detail`). Filtering on the declared stage rather
|
||||
// than on `affects()` means the shader and the stage agree by
|
||||
// construction — there is one place an operation says which it is.
|
||||
let active: Vec<&dyn Operation> = ops
|
||||
.iter()
|
||||
.map(|o| o.as_ref())
|
||||
.filter(|o| o.is_active())
|
||||
.filter(|o| o.is_active() && o.detail().is_none())
|
||||
.collect();
|
||||
|
||||
// Whether a detail stage follows. If one does, this pass stops short of
|
||||
// the output transform and hands on a linear intermediate; the last detail
|
||||
// pass finishes the job. Decided from the operations themselves rather
|
||||
// than from a flag the caller sets, because a caller that got the flag
|
||||
// wrong would produce a shader whose storage format does not match the
|
||||
// texture bound to it.
|
||||
let output_mode = if ops
|
||||
.iter()
|
||||
.any(|o| o.is_active() && o.detail().is_some())
|
||||
{
|
||||
OutputMode::LinearWorking
|
||||
} else {
|
||||
OutputMode::Encoded
|
||||
};
|
||||
|
||||
let mut uniform_fields = String::new();
|
||||
let mut uniform_values: Vec<f32> = Vec::new();
|
||||
let mut body = String::new();
|
||||
@@ -328,8 +564,40 @@ pub fn compose_full(
|
||||
""
|
||||
};
|
||||
|
||||
let to_output = primaries_conversion(output);
|
||||
let encode_output = encode_output_fn(output);
|
||||
// The tail, and it is the whole of the difference between the two output
|
||||
// modes. Everything above — the prologue, the fragments, the mask layers,
|
||||
// the camera matrix — is emitted identically either way, so an operation
|
||||
// cannot tell whether a detail stage follows it and does not have to.
|
||||
let (store_format, to_output, encode_output, store) = match output_mode {
|
||||
OutputMode::Encoded => (
|
||||
"rgba8unorm",
|
||||
primaries_conversion(output),
|
||||
encode_output_fn(output),
|
||||
" // Clip to the output gamut and encode. The clip is last for the reason the
|
||||
// matrix above is: a colour outside sRGB is still inside a wider space, and
|
||||
// clipping before the conversion would throw it away for no one's benefit.
|
||||
c = clamp(c, vec3<f32>(0.0), vec3<f32>(1.0));
|
||||
textureStore(output, vec2<i32>(gid.xy), vec4<f32>(encode_output(c), 1.0));"
|
||||
.to_string(),
|
||||
),
|
||||
OutputMode::LinearWorking => (
|
||||
"rgba16float",
|
||||
String::new(),
|
||||
String::new(),
|
||||
" // Stop here: a detail stage follows, and it needs linear values it
|
||||
// can average. No primaries conversion, no clip and no encode — the
|
||||
// last detail pass performs all three, so the pipeline still quantises
|
||||
// exactly once (FR-DEV-2).
|
||||
//
|
||||
// Deliberately *not* clamped. A recovered highlight is above 1.0 at this
|
||||
// point and an out-of-gamut colour can be below 0.0; clipping them here
|
||||
// would put a hard edge into the very neighbourhood the next pass is
|
||||
// about to convolve, which is how sharpeners come to draw dark rings
|
||||
// around specular highlights.
|
||||
textureStore(output, vec2<i32>(gid.xy), vec4<f32>(c, 1.0));"
|
||||
.to_string(),
|
||||
),
|
||||
};
|
||||
|
||||
let source = format!(
|
||||
"// GENERATED — do not edit.
|
||||
@@ -344,7 +612,7 @@ struct Params {{
|
||||
|
||||
@group(0) @binding(0) var source: texture_2d<f32>;
|
||||
@group(0) @binding(1) var<uniform> u: Params;
|
||||
@group(0) @binding(2) var output: texture_storage_2d<rgba8unorm, write>;
|
||||
@group(0) @binding(2) var output: texture_storage_2d<{store_format}, write>;
|
||||
// The local adjustment masks, one array layer each, rasterised by a separate
|
||||
// pass (ARCH §5.4). Declared unconditionally even when no layer is active, so
|
||||
// that every generated shader shares one bind group layout — a layout that
|
||||
@@ -430,11 +698,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{
|
||||
dot(u.cam_to_srgb_2.rgb, c),
|
||||
);
|
||||
{to_output}
|
||||
// Clip to the output gamut and encode. The clip is last for the reason the
|
||||
// matrix above is: a colour outside sRGB is still inside a wider space, and
|
||||
// clipping before the conversion would throw it away for no one's benefit.
|
||||
c = clamp(c, vec3<f32>(0.0), vec3<f32>(1.0));
|
||||
textureStore(output, vec2<i32>(gid.xy), vec4<f32>(encode_output(c), 1.0));
|
||||
{store}
|
||||
}}
|
||||
",
|
||||
active.len()
|
||||
@@ -473,6 +737,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{
|
||||
source,
|
||||
uniforms: uniform_values,
|
||||
structure_hash,
|
||||
output_mode,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,7 +754,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {{
|
||||
/// value it already had. The identity is detected rather than special-cased by
|
||||
/// name, so a space that happens to share sRGB's primaries would be spared
|
||||
/// too.
|
||||
fn primaries_conversion(output: ColourSpace) -> String {
|
||||
pub(crate) fn primaries_conversion(output: ColourSpace) -> String {
|
||||
let m = output.from_linear_srgb();
|
||||
const IDENTITY: [f32; 9] = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0];
|
||||
// A tolerance rather than equality: the matrix is an inverse multiplied by
|
||||
@@ -528,7 +793,7 @@ fn primaries_conversion(output: ColourSpace) -> String {
|
||||
///
|
||||
/// Named `encode_output` whatever the space, so the call site at the end of
|
||||
/// `main` does not have to know which one it got.
|
||||
fn encode_output_fn(output: ColourSpace) -> String {
|
||||
pub(crate) fn encode_output_fn(output: ColourSpace) -> String {
|
||||
let body = match output.transfer() {
|
||||
Transfer::Srgb => " let lo = c * 12.92;
|
||||
let hi = 1.055 * pow(max(c, vec3<f32>(0.0031308)), vec3<f32>(1.0 / 2.4)) - 0.055;
|
||||
@@ -626,7 +891,7 @@ const BILINEAR_HELPER: &str = "fn sample_bilinear(uv: vec2<f32>, dims: vec2<u32>
|
||||
";
|
||||
|
||||
/// Fold a value into a hash. FNV-1a's mixing step, over eight bytes.
|
||||
fn mix(mut h: u64, value: u64) -> u64 {
|
||||
pub(crate) fn mix(mut h: u64, value: u64) -> u64 {
|
||||
for byte in value.to_le_bytes() {
|
||||
h ^= u64::from(byte);
|
||||
h = h.wrapping_mul(0x100_0000_01b3);
|
||||
@@ -644,7 +909,7 @@ fn mix(mut h: u64, value: u64) -> u64 {
|
||||
/// Still integer state hashed on the CPU, as ARCH §6.13 requires of a cache
|
||||
/// key: the text is generated from parameters that are neutral or not, never
|
||||
/// from a rendered float.
|
||||
fn hash_source(source: &str) -> u64 {
|
||||
pub(crate) fn hash_source(source: &str) -> u64 {
|
||||
// FNV-1a: no dependency, stable across runs and platforms, which the
|
||||
// shader cache key requires.
|
||||
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
|
||||
@@ -1051,4 +1316,46 @@ mod tests {
|
||||
let shader = compose(&[fake(&DESC_A, 1.0, false)]);
|
||||
assert!(shader.source.starts_with("// GENERATED"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detail_operations_agree_with_themselves() {
|
||||
// An operation says which stage it belongs to in two places — through
|
||||
// `affects()` and through `detail()` — and the two must say the same
|
||||
// thing. Disagreement is the worst possible failure mode here, because
|
||||
// it is silent: an operation claiming `Affects::Detail` while
|
||||
// returning `None` from `detail()` is fused as a point op and asked
|
||||
// for a fragment it does not have, and one returning `Some` while
|
||||
// claiming `Affects::Colour` is filtered out of the fused pass and put
|
||||
// in the wrong invalidation bucket. Either way the slider moves and
|
||||
// nothing happens.
|
||||
//
|
||||
// Checked over the real chain, plus the test consumer, so that a
|
||||
// sharpening operation added later is covered by this without anyone
|
||||
// remembering to extend it.
|
||||
let mut ops = crate::ops::chain();
|
||||
ops.push(Box::new(crate::detail::probe::BoxBlur::new()));
|
||||
for op in &ops {
|
||||
let id = op.descriptor().id;
|
||||
assert_eq!(
|
||||
op.detail().is_some(),
|
||||
op.affects() == Affects::Detail,
|
||||
"{id} disagrees with itself about whether it is a \
|
||||
neighbourhood operation"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_detail_operation_never_contributes_a_fused_uniform() {
|
||||
// Slot order in the generated block is emission order, and nothing
|
||||
// addresses a slot by number — so an operation that contributed a
|
||||
// uniform without contributing the fragment that reads it would shift
|
||||
// every later operation's uniforms out from under its shader. The
|
||||
// filter in `compose_full` prevents it; this is the assertion that the
|
||||
// filter is on the right side of the loop.
|
||||
let mut ops = crate::ops::chain();
|
||||
ops.push(Box::new(crate::detail::probe::BoxBlur::with_radius(0.05)));
|
||||
let before = compose(&crate::ops::chain()).uniforms.len();
|
||||
assert_eq!(compose(&ops).uniforms.len(), before);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user