Hand out descriptors a declaration could produce
`Operation::descriptor()` returned `&'static OpDescriptor`, and that lifetime
is the whole reason a build-time node is free and a run-time node is
impossible: only a compile-time literal can satisfy it, so no amount of
reading `ops/*.yaml` at startup could ever produce a descriptor the rest of
the application would accept. FR-PLG-2 says a bundled operation and a
third-party plugin are the same kind of thing, differing only in where the
file was found — and a lifetime outsiders cannot meet is exactly the second,
weaker format that requirement forbids.
So a descriptor is now owned and handed out as `Arc<OpDescriptor>`, with `Vec`
where it held `&'static` slices. `Arc` rather than a `&self`-borrowed
reference because the callers want to *keep* it: the develop panel collects
descriptors and then mutates the graph, and a borrow would tie the
descriptor's lifetime to a borrow of the operation it came from, which is the
one thing `&'static` was doing right.
The identifier newtypes deliberately did not follow. `ParamId` is `Copy`, is
compared in `match` arms against generated constants, is a map key in the
sidecar and history, and reaches Slint model rows; an `Arc<str>` there would
cost a refcount on every one of those and would take `match id { EXPOSURE =>
.. }` away from the generated code. They gain an interner instead, which is
honest about its lifetime rather than pretending to one — the set of ids is
bounded by deduplication and is process-lifetime by construction, because the
sidecar on disk names its parameters and an id has to stay resolvable for as
long as any edit naming it can be opened.
No behaviour changes. Every descriptor that was a `static` is a `LazyLock`
initialiser now, `Operation::helpers` borrows from `self` instead of being
`'static` so a future run-time node can own its list, and `Warp` and `Framing`
follow `Operation` so there is one shape rather than two.
The one place a descriptor is read per frame is `compose_full`, which takes
`descriptor().id` to prefix each active operation's uniforms, and `dr-ui`
composes on every frame it draws. That is a dozen atomic increments beside a
composition that is already building several kilobytes of WGSL on the same
call; it is noted at the trait method rather than left for a profiler to find.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
//! the band acts at full strength right up to a hard edge; and with two bands
|
||||
//! adjusted, each one's share depends on what the other is set to, so turning
|
||||
//! up one colour's saturation quietly weakened its neighbour's hue shift.
|
||||
use std::sync::{Arc, LazyLock};
|
||||
|
||||
use crate::descriptor::{
|
||||
Attribute, Facet, LocalizedKey, OpDescriptor, OpId, ParamDescriptor, ParamId,
|
||||
@@ -123,8 +124,9 @@ impl Channel {
|
||||
}
|
||||
|
||||
// Parameter descriptors, one per band per channel. Written out rather than
|
||||
// generated because `ParamDescriptor` must be `const` to live in a `static`,
|
||||
// and a const loop cannot build a slice. The macro keeps it honest.
|
||||
// looped because `concat!` needs literals: every id is built from its band's
|
||||
// key, and a runtime loop has no way to spell `orange_sat`. The macro keeps it
|
||||
// honest.
|
||||
//
|
||||
// **Every one of them is faceted**, and that is what makes the operation
|
||||
// legible in a panel. Thirty-six parameters presented as a flat list are
|
||||
@@ -137,7 +139,7 @@ impl Channel {
|
||||
// §4.3a); this only says the parameter acts on the band centred there.
|
||||
macro_rules! band_params {
|
||||
($(($key:literal, $hue:literal)),* $(,)?) => {
|
||||
&[
|
||||
vec![
|
||||
$(
|
||||
ParamDescriptor::amount(
|
||||
concat!($key, "_hue"),
|
||||
@@ -175,25 +177,27 @@ macro_rules! band_params {
|
||||
// the same reason as those: `concat!` needs literals, so the keys and hues
|
||||
// cannot be read out of `BANDS` here. `facets_match_their_bands` below is
|
||||
// what keeps them from drifting.
|
||||
static DESCRIPTOR: OpDescriptor = OpDescriptor {
|
||||
attributes: &[Attribute::Colour],
|
||||
id: ID,
|
||||
label: LocalizedKey("op.colour_mixer"),
|
||||
params: band_params![
|
||||
("red", 0.0),
|
||||
("orange", 30.0),
|
||||
("yellow", 60.0),
|
||||
("chartreuse", 90.0),
|
||||
("green", 120.0),
|
||||
("spring", 150.0),
|
||||
("cyan", 180.0),
|
||||
("azure", 210.0),
|
||||
("blue", 240.0),
|
||||
("violet", 270.0),
|
||||
("magenta", 300.0),
|
||||
("rose", 330.0),
|
||||
],
|
||||
};
|
||||
static DESCRIPTOR: LazyLock<Arc<OpDescriptor>> = LazyLock::new(|| {
|
||||
Arc::new(OpDescriptor {
|
||||
attributes: vec![Attribute::Colour],
|
||||
id: ID,
|
||||
label: LocalizedKey("op.colour_mixer"),
|
||||
params: band_params![
|
||||
("red", 0.0),
|
||||
("orange", 30.0),
|
||||
("yellow", 60.0),
|
||||
("chartreuse", 90.0),
|
||||
("green", 120.0),
|
||||
("spring", 150.0),
|
||||
("cyan", 180.0),
|
||||
("azure", 210.0),
|
||||
("blue", 240.0),
|
||||
("violet", 270.0),
|
||||
("magenta", 300.0),
|
||||
("rose", 330.0),
|
||||
],
|
||||
})
|
||||
});
|
||||
|
||||
static MIXER_HELPERS: &[Helper] = &[
|
||||
helpers::LUMINANCE,
|
||||
@@ -306,8 +310,8 @@ impl ColourMixer {
|
||||
}
|
||||
|
||||
impl Operation for ColourMixer {
|
||||
fn descriptor(&self) -> &'static OpDescriptor {
|
||||
&DESCRIPTOR
|
||||
fn descriptor(&self) -> Arc<OpDescriptor> {
|
||||
DESCRIPTOR.clone()
|
||||
}
|
||||
|
||||
fn set_param(&mut self, id: ParamId, value: f32) {
|
||||
@@ -505,7 +509,7 @@ mod tests {
|
||||
fn every_descriptor_id_resolves_to_a_band_and_channel() {
|
||||
// The link between the descriptor list and the value array. A
|
||||
// mismatch would make a slider silently adjust nothing.
|
||||
for p in DESCRIPTOR.params {
|
||||
for p in &DESCRIPTOR.params {
|
||||
assert!(
|
||||
ColourMixer::index_of(p.id).is_some(),
|
||||
"{} does not map to a band",
|
||||
@@ -547,7 +551,7 @@ mod tests {
|
||||
// and a hue mistyped there would put a row's swatch on a colour the
|
||||
// band does not act on — a control that lies about what it edits,
|
||||
// which is worse than one with no swatch at all.
|
||||
for p in DESCRIPTOR.params {
|
||||
for p in &DESCRIPTOR.params {
|
||||
let facet = p.facet.expect("every mixer parameter is faceted");
|
||||
let (band_key, _) = p.id.0.rsplit_once('_').expect("id is band_channel");
|
||||
let band = BANDS
|
||||
@@ -577,7 +581,7 @@ mod tests {
|
||||
// the aspect keyed per band, grouping by it would produce thirty-six
|
||||
// groups of one and nothing would have been gained.
|
||||
let mut per_aspect = std::collections::BTreeMap::new();
|
||||
for p in DESCRIPTOR.params {
|
||||
for p in &DESCRIPTOR.params {
|
||||
let facet = p.facet.expect("faceted");
|
||||
*per_aspect.entry(facet.aspect.0).or_insert(0) += 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user