Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

fix(effects): a hostile package is refused for real - tried on the GPU at install, its pipeline errors caught, its bindings typed, its chain kept off files

Jareer165da4ec3513
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index 8458f81b..4f5b7ada 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -140,8 +140,13 @@ At load, `concat-effects/src/shader.rs` stitches the host's prelude round the
package body, parses and validates it with naga, reads the `Params` layout for
the uniform buffer, and refuses a shader that binds anything the host did not
declare or loops without a break. A look-up table larger than 65 a side is
-refused too. The GPU compositor can run a package once on a sixteen-pixel
-picture against a timeout (`WgpuCompositor::trial`) before it is enabled.
+refused too, and a binding declared as anything other than what the host
+puts there, and a chain that names a file other than its own `{lut}`. When
+the window loads the user's packages it runs each one's shader once on the
+GPU over a 512-pixel picture against a three-second timeout
+(`Catalogue::install_with`, `WgpuCompositor::trial_at`) and leaves out one
+that fails; a pipeline the driver refuses at draw time is caught in an
+error scope and the pass skipped, never an uncaptured error.
## 4. Decoding, caching and scheduling
diff --git a/src/crates/concat-core/src/shader.rs b/src/crates/concat-core/src/shader.rs
index 04fd137a..a05e7700 100644
--- a/src/crates/concat-core/src/shader.rs
+++ b/src/crates/concat-core/src/shader.rs
@@ -32,8 +32,9 @@ pub struct ShaderPass {
/// stage keys its own kernel for the package by.
pub package: String,
/// What to cache the compiled pipeline under: the package's id and
- /// version, so a package that changes its shader gets a new pipeline
- /// and one that only changes its knobs keeps the old.
+ /// version and a fingerprint of its source, so a package that changes
+ /// its shader gets a new pipeline - version bump or not - and one that
+ /// only changes its knobs keeps the old.
pub key: String,
/// The complete WGSL module: the host's prelude with the package's body,
/// declaring `fn effect(uv: vec2<f32>) -> vec4<f32>`.
diff --git a/src/crates/concat-effects/src/catalogue.rs b/src/crates/concat-effects/src/catalogue.rs
index 65aded9e..1bfd5de2 100644
--- a/src/crates/concat-effects/src/catalogue.rs
+++ b/src/crates/concat-effects/src/catalogue.rs
@@ -230,6 +230,15 @@ impl Package {
known.push(name.to_owned());
lets.push((name.to_owned(), expr));
}
+ // A filter that reads a file reads it with the host's
+ // rights: the only file a chain may name is the package's
+ // own look-up table, and only through `{lut}`.
+ if let Some(option) = names_a_file(&ffmpeg.chain) {
+ return Err(invalid(format!(
+ "chain names a file through `{option}`: a package's chain may read \
+ its own look-up table as `{{lut}}` and no other file"
+ )));
+ }
let template = Template::parse(&ffmpeg.chain)
.map_err(|error| invalid(format!("chain: {error}")))?;
let mut names = Vec::new();
@@ -432,6 +441,15 @@ impl Package {
self.manifest.effect.kind
}
+ /// The pass this package's shader makes at its defaults: what a vet
+ /// runs once before the package is offered. None for a package with
+ /// no shader.
+ pub fn trial_pass(&self) -> Option<ShaderPass> {
+ let shader = self.shader.as_ref()?;
+ let values = self.resolve(&BTreeMap::new());
+ Some(shader.pass(&values, &self.manifest.params, 1.0, self.lut.clone(), None))
+ }
+
/// The shader, when the package renders on the GPU.
pub fn shader(&self) -> Option<&Shader> {
self.shader.as_ref()
@@ -655,6 +673,26 @@ impl Package {
}
}
+/// The option a chain names a file through, if it does: `file=`,
+/// `psfile=` and `filename=` are how FFmpeg's filters take one, and the
+/// only value a package may give is its own table, `{lut}`.
+fn names_a_file(chain: &str) -> Option<&'static str> {
+ const OPTIONS: [&str; 3] = ["file=", "psfile=", "filename="];
+ for option in OPTIONS {
+ let mut rest = chain;
+ while let Some(at) = rest.find(option) {
+ let before = rest[..at].chars().next_back();
+ let value = &rest[at + option.len()..];
+ let named = before.is_none_or(|c| !c.is_alphanumeric() && c != '_');
+ if named && !value.starts_with("{lut}") {
+ return Some(option);
+ }
+ rest = &rest[at + option.len()..];
+ }
+ }
+ None
+}
+
/// A number that changes when anything in the package folders under `dir`
/// does: a folder added or taken away, a file in one written, added or
/// removed. What a watcher polls, cheaply - a stat per file, no reading -
@@ -762,17 +800,52 @@ impl Catalogue {
/// afresh and leaks the last one, which is a few kilobytes a time and
/// what keeps every caller's `&'static` honest.
pub fn install(dir: &Path) -> Vec<Error> {
+ Self::install_with(dir, &mut |_| Ok(()))
+ }
+
+ /// [`Catalogue::install`], with every package the folder holds put to
+ /// `vet` before it is offered: one the vet refuses is left out and
+ /// reported the way one that failed to parse is. The window's vet runs
+ /// a package's shader once on the GPU against a timeout, so a shader
+ /// that hangs the device is found at install, not on the first frame
+ /// that asks for it (audit 2026-09-23, #7).
+ pub fn install_with(
+ dir: &Path,
+ vet: &mut dyn FnMut(&Package) -> Result<(), String>,
+ ) -> Vec<Error> {
let mut catalogue = Catalogue::compiled_in();
- let errors = if dir.is_dir() {
+ let mut errors = if dir.is_dir() {
catalogue.load_dir(dir)
} else {
Vec::new()
};
+ let refused: Vec<(String, String)> = catalogue
+ .packages
+ .iter()
+ .filter(|package| package.folder.is_some())
+ .filter_map(|package| vet(package).err().map(|why| (package.id().to_owned(), why)))
+ .collect();
+ for (id, message) in refused {
+ catalogue.remove(&id);
+ errors.push(Error::Invalid { id, message });
+ }
let built: &'static Catalogue = Box::leak(Box::new(catalogue));
*CURRENT.write().expect("catalogue lock") = Some(built);
errors
}
+ /// Takes a package out, by id, and reindexes what is left.
+ fn remove(&mut self, id: &str) {
+ self.packages.retain(|package| package.id() != id);
+ self.by_id.clear();
+ for (index, package) in self.packages.iter().enumerate() {
+ self.by_id.insert(package.id().to_owned(), index);
+ for alias in &package.manifest.effect.aliases {
+ self.by_id.insert(alias.clone(), index);
+ }
+ }
+ }
+
/// The packages compiled into the binary, and nothing else.
fn compiled_in() -> Catalogue {
let mut catalogue = Catalogue::new();
@@ -1006,3 +1079,23 @@ impl Catalogue {
fragments.join(",")
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// A chain reads the frame and its own table and no other file.
+ #[test]
+ fn a_chain_that_names_a_file_is_refused() {
+ assert_eq!(names_a_file("lut3d=file={lut}:interp=tetrahedral"), None);
+ assert_eq!(names_a_file("hue=h=10,eq=brightness=0.1"), None);
+ assert_eq!(names_a_file("lut3d=file=/etc/passwd"), Some("file="));
+ assert_eq!(names_a_file("curves=psfile=/tmp/x.acv"), Some("psfile="));
+ assert_eq!(names_a_file("lut1d=filename=x.cube"), Some("filename="));
+ assert_eq!(
+ names_a_file("scale=profile=1"),
+ None,
+ "an option that merely ends in the word"
+ );
+ }
+}
diff --git a/src/crates/concat-effects/src/shader.rs b/src/crates/concat-effects/src/shader.rs
index a862786f..fc372595 100644
--- a/src/crates/concat-effects/src/shader.rs
+++ b/src/crates/concat-effects/src/shader.rs
@@ -414,7 +414,7 @@ impl Shader {
let (source, slots, span) = stitch(manifest, body, Entry::Effect, PRELUDE, POSTLUDE)?;
Ok(Shader {
package: manifest.effect.id.clone(),
- key: format!("{}@{}", manifest.effect.id, manifest.effect.version),
+ key: pipeline_key(&manifest.effect.id, manifest.effect.version, &source),
source,
slots,
span,
@@ -457,40 +457,98 @@ impl Shader {
}
}
-/// The bindings a prelude declares, and the only ones a package may use.
-/// The union of both contracts: an effect's layer at group 0 (0,0)-(0,1)
-/// and a transition's two pictures at group 0 (0,0)-(0,3); the frame block
-/// and parameters at group 1; the look-up table at group 2; an effect's
-/// reveal map at group 3 - a transition has no group 3, so nothing there
-/// ever validates against a transition's module.
-const BINDINGS: [(u32, u32); 10] = [
- (0, 0),
- (0, 1),
- (0, 2),
- (0, 3),
- (1, 0),
- (1, 1),
- (2, 0),
- (2, 1),
- (3, 0),
- (3, 1),
-];
+/// What the host binds at one slot.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+enum Bound {
+ /// A 2D float texture: a layer, a transition's picture, a reveal map.
+ Picture,
+ /// The 3D float texture of a look-up table.
+ Table,
+ /// A plain (non-comparison) sampler.
+ Sampler,
+ /// A uniform block: the frame, the parameters.
+ Uniform,
+}
+
+impl Bound {
+ fn name(self) -> &'static str {
+ match self {
+ Bound::Picture => "a 2D texture",
+ Bound::Table => "a 3D texture",
+ Bound::Sampler => "a sampler",
+ Bound::Uniform => "a uniform block",
+ }
+ }
+}
+
+/// What the host provides at `(group, binding)` for `entry`, and so the
+/// only thing a package may declare there: an effect's layer at (0,0)-(0,1)
+/// and its reveal map at group 3; a transition's two pictures at (0,0)-(0,3)
+/// and nothing at group 3; the frame block and parameters at group 1 and
+/// the look-up table at group 2 for both. A slot outside this, or one
+/// declared as something else, is a pipeline the device cannot build.
+fn provided(entry: Entry, group: u32, binding: u32) -> Option<Bound> {
+ match (entry, group, binding) {
+ (_, 0, 0) => Some(Bound::Picture),
+ (_, 0, 1) => Some(Bound::Sampler),
+ (Entry::Transition, 0, 2) => Some(Bound::Picture),
+ (Entry::Transition, 0, 3) => Some(Bound::Sampler),
+ (_, 1, 0) | (_, 1, 1) => Some(Bound::Uniform),
+ (_, 2, 0) => Some(Bound::Table),
+ (_, 2, 1) => Some(Bound::Sampler),
+ (Entry::Effect, 3, 0) => Some(Bound::Picture),
+ (Entry::Effect, 3, 1) => Some(Bound::Sampler),
+ _ => None,
+ }
+}
+
+/// What a global variable is declared as, in the host's terms.
+fn declared(module: &naga::Module, global: &naga::GlobalVariable) -> Option<Bound> {
+ match &module.types[global.ty].inner {
+ naga::TypeInner::Image {
+ dim,
+ arrayed: false,
+ class:
+ naga::ImageClass::Sampled {
+ kind: naga::ScalarKind::Float,
+ multi: false,
+ },
+ } => match dim {
+ naga::ImageDimension::D2 => Some(Bound::Picture),
+ naga::ImageDimension::D3 => Some(Bound::Table),
+ _ => None,
+ },
+ naga::TypeInner::Sampler { comparison: false } => Some(Bound::Sampler),
+ _ if global.space == naga::AddressSpace::Uniform => Some(Bound::Uniform),
+ _ => None,
+ }
+}
/// What a package may not do, however well it parses: bind anything the
-/// host did not declare, or loop without an end. A community shader runs
-/// on the person's GPU with the host's rights, and a loop with no bound
+/// host did not declare, bind a slot as something other than what the
+/// host puts there, or loop without an end. A community shader runs on
+/// the person's GPU with the host's rights, and a loop with no bound
/// hangs the device for every process on the machine; a binding the host
/// does not know is one it cannot serve. Caught at load, where a broken
/// package is a load error and not a black frame.
-fn budget(module: &naga::Module) -> Result<(), String> {
+fn budget(module: &naga::Module, entry: Entry) -> Result<(), String> {
for (_, global) in module.global_variables.iter() {
- if let Some(binding) = &global.binding
- && !BINDINGS.contains(&(binding.group, binding.binding))
- {
+ let Some(binding) = &global.binding else {
+ continue;
+ };
+ let Some(wanted) = provided(entry, binding.group, binding.binding) else {
return Err(format!(
"the shader binds @group({}) @binding({}), which the host does not provide",
binding.group, binding.binding
));
+ };
+ if declared(module, global) != Some(wanted) {
+ return Err(format!(
+ "the shader binds @group({}) @binding({}) as something other than {}, which is what the host provides there",
+ binding.group,
+ binding.binding,
+ wanted.name()
+ ));
}
}
for (_, function) in module.functions.iter() {
@@ -548,6 +606,17 @@ fn breaks(block: &naga::Block) -> bool {
})
}
+/// What a compiled pipeline is cached under: the package's id and version,
+/// and a fingerprint of the stitched source, so a shader edited in place
+/// without a version bump still gets a pipeline of its own rather than
+/// the stale one a running compositor holds.
+fn pipeline_key(id: &str, version: u32, source: &str) -> String {
+ use std::hash::{Hash, Hasher};
+ let mut hasher = std::collections::hash_map::DefaultHasher::new();
+ source.hash(&mut hasher);
+ format!("{id}@{version}#{:016x}", hasher.finish())
+}
+
fn is_f32(scalar: &naga::Scalar) -> bool {
scalar.kind == naga::ScalarKind::Float && scalar.width == 4
}
@@ -610,9 +679,12 @@ fn stitch(
let module =
naga::front::wgsl::parse_str(&source).map_err(|error| error.emit_to_string(&source))?;
+ // The baseline capabilities and nothing more: a shader that needs an
+ // extension is refused here, by name, rather than by whichever device
+ // it first meets.
let mut validator = naga::valid::Validator::new(
naga::valid::ValidationFlags::all(),
- naga::valid::Capabilities::all(),
+ naga::valid::Capabilities::empty(),
);
validator
.validate(&module)
@@ -624,7 +696,7 @@ fn stitch(
{
return Err(format!("the shader declares no `{}`", entry.signature()));
}
- budget(&module)?;
+ budget(&module, entry)?;
let (members, span) = module
.types
@@ -865,7 +937,7 @@ impl TransitionShader {
TRANSITION_POSTLUDE,
)?;
Ok(TransitionShader {
- key: format!("{}@{}", manifest.effect.id, manifest.effect.version),
+ key: pipeline_key(&manifest.effect.id, manifest.effect.version, &source),
source,
slots,
span,
@@ -950,7 +1022,7 @@ fn effect(uv: vec2<f32>) -> vec4<f32> {
"#,
)
.expect("compiles");
- assert_eq!(shader.key, "test.thing@1");
+ assert!(shader.key.starts_with("test.thing@1#"), "{}", shader.key);
assert!(shader.source().contains("fn fs_main"));
// radius first at 0, amount at 4; the buffer padded to sixteen.
let mut values = BTreeMap::new();
@@ -1071,7 +1143,7 @@ fn transition(uv: vec2<f32>, progress: f32) -> vec4<f32> {
"#,
)
.expect("compiles");
- assert_eq!(shader.key, "test.wipe@1");
+ assert!(shader.key.starts_with("test.wipe@1#"), "{}", shader.key);
assert!(shader.source().contains("fn fs_main"));
assert!(shader.source().contains("frame.progress"));
assert!(shader.source().contains("to_texture"));
@@ -1094,4 +1166,50 @@ fn transition(uv: vec2<f32>, progress: f32) -> vec4<f32> {
);
assert!(no_entry.unwrap_err().contains("fn transition"));
}
+
+ /// A shader may only declare the slots the host fills, as what the
+ /// host puts there: an effect has no group 0 binding 2, and a sampler
+ /// at group 3 binding 0 is not the reveal map that lives there.
+ #[test]
+ fn a_binding_of_the_wrong_kind_or_the_wrong_entry_is_refused() {
+ let manifest = Manifest::parse(
+ "[effect]\nid = \"test.bind\"\nname = \"Bind\"\nkind = \"effect\"\n[wgsl]\nentry = \"effect.wgsl\"\n",
+ )
+ .expect("a manifest");
+ let wrong_kind = Shader::compile(
+ &manifest,
+ "@group(3) @binding(0) var extra: sampler;\nfn effect(uv: vec2<f32>) -> vec4<f32> { return sample(uv); }",
+ );
+ let message = wrong_kind.expect_err("a sampler where a picture goes");
+ assert!(message.contains("@group(3) @binding(0)"), "{message}");
+ assert!(message.contains("2D texture"), "{message}");
+ let wrong_entry = Shader::compile(
+ &manifest,
+ "@group(0) @binding(2) var other: texture_2d<f32>;\nfn effect(uv: vec2<f32>) -> vec4<f32> { return sample(uv); }",
+ );
+ let message = wrong_entry.expect_err("a transition's slot in an effect");
+ assert!(message.contains("does not provide"), "{message}");
+ }
+
+ /// The pipeline key follows the source, so a shader edited without a
+ /// version bump does not keep a stale pipeline.
+ #[test]
+ fn the_key_changes_with_the_source() {
+ let manifest = Manifest::parse(
+ "[effect]\nid = \"test.key\"\nname = \"Key\"\nkind = \"effect\"\n[wgsl]\nentry = \"effect.wgsl\"\n",
+ )
+ .expect("a manifest");
+ let one = Shader::compile(
+ &manifest,
+ "fn effect(uv: vec2<f32>) -> vec4<f32> { return sample(uv); }",
+ )
+ .expect("compiles");
+ let two = Shader::compile(
+ &manifest,
+ "fn effect(uv: vec2<f32>) -> vec4<f32> { return sample(uv) * 0.5; }",
+ )
+ .expect("compiles");
+ assert_ne!(one.key, two.key);
+ assert!(one.key.starts_with("test.key@1#"));
+ }
}
diff --git a/src/crates/concat-host/src/preview.rs b/src/crates/concat-host/src/preview.rs
index 9c57737c..c6a8f80e 100644
--- a/src/crates/concat-host/src/preview.rs
+++ b/src/crates/concat-host/src/preview.rs
@@ -95,6 +95,22 @@ impl Monitor {
}
}
+ /// Runs `pass` once on the window's device over a picture `side`
+ /// pixels square, against `timeout`: what a custom package's shader
+ /// survives before the package is offered. None without a GPU, where
+ /// there is nothing to run it on.
+ #[cfg(feature = "gpu")]
+ pub fn trial(
+ &self,
+ pass: &concat_core::shader::ShaderPass,
+ side: u32,
+ timeout: std::time::Duration,
+ ) -> Option<Result<(), String>> {
+ let gpu = self.gpu.as_ref()?;
+ let mut gpu = gpu.lock().unwrap_or_else(|poisoned| poisoned.into_inner());
+ Some(gpu.trial_at(pass, side, timeout))
+ }
+
/// Whether frames can be composited on the GPU.
pub fn has_gpu(&self) -> bool {
#[cfg(feature = "gpu")]
diff --git a/src/crates/concat-render/src/gpu.rs b/src/crates/concat-render/src/gpu.rs
index 5ec3f5cd..13fb3be7 100644
--- a/src/crates/concat-render/src/gpu.rs
+++ b/src/crates/concat-render/src/gpu.rs
@@ -203,6 +203,9 @@ pub struct WgpuCompositor {
shaders: HashMap<String, CompiledShader>,
/// Compiled transitions by their key; see `TransitionPass::key`.
transitions: HashMap<String, CompiledShader>,
+ /// Passes and transitions the driver refused a pipeline for, by key:
+ /// tried once, skipped from then on, never asked for again.
+ refused: std::collections::HashSet<String>,
sampler: wgpu::Sampler,
vertices: wgpu::Buffer,
vertex_capacity: usize,
@@ -486,6 +489,7 @@ impl WgpuCompositor {
reveals: HashMap::new(),
shaders: HashMap::new(),
transitions: HashMap::new(),
+ refused: std::collections::HashSet::new(),
sampler,
vertices,
vertex_capacity: 6 * 8,
@@ -848,22 +852,40 @@ impl WgpuCompositor {
/// this compositor is dead from then on, since a device mid-hang
/// cannot be trusted with the next frame.
pub fn trial(&mut self, pass: &ShaderPass, timeout: std::time::Duration) -> Result<(), String> {
+ self.trial_at(pass, 16, timeout)
+ }
+
+ /// [`WgpuCompositor::trial`] over a picture `side` pixels square. A
+ /// loop that is bounded but enormous costs a sixteen-pixel trial
+ /// nothing and a real frame minutes; a trial at a few hundred pixels
+ /// a side is what tells the two apart (audit 2026-09-23, #7).
+ pub fn trial_at(
+ &mut self,
+ pass: &ShaderPass,
+ side: u32,
+ timeout: std::time::Duration,
+ ) -> Result<(), String> {
if self.dead {
return Err("the GPU device is dead".to_owned());
}
- let mut picture = Frame::transparent(16, 16);
+ let side = side.max(1);
+ let mut picture = Frame::transparent(side, side);
picture.fill([128, 96, 64, 255]);
let mut layer =
PlannedLayer::picture(crate::plan::detached_clip(), std::sync::Arc::new(picture));
layer.effects = vec![pass.clone()];
let plan = FramePlan {
layers: vec![layer],
- ..FramePlan::empty(16, 16)
+ ..FramePlan::empty(side, side)
};
let scope = self.device.push_error_scope(wgpu::ErrorFilter::Validation);
let (draws, vertices) = self.prepare(&plan);
+ if self.refused.contains(&pass.key) {
+ let _ = pollster::block_on(scope.pop());
+ return Err("the driver refused the pass's pipeline".to_owned());
+ }
self.write_vertices(&vertices);
- let texture = self.presentable(16, 16);
+ let texture = self.presentable(side, side);
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
let encoder = self.encode(&view, &draws, wgpu::Color::BLACK);
self.queue.submit([encoder.finish()]);
@@ -1090,12 +1112,15 @@ impl WgpuCompositor {
/// The compiled pipeline for a pass, built the first time its key is
/// seen. The catalogue validated the module at load, so a failure here
- /// is a driver disagreement; wgpu reports it through its error scope and
- /// the pass draws nothing rather than the frame being lost.
+ /// is a driver disagreement: it is caught in an error scope, logged,
+ /// and the pass is skipped from then on - the layer draws untreated -
+ /// rather than reaching wgpu's uncaptured-error handler, which ends
+ /// the process (audit 2026-09-23, #7).
fn shader(&mut self, pass: &ShaderPass) {
- if self.shaders.contains_key(&pass.key) {
+ if self.shaders.contains_key(&pass.key) || self.refused.contains(&pass.key) {
return;
}
+ let scope = self.device.push_error_scope(wgpu::ErrorFilter::Validation);
let module = self
.device
.create_shader_module(wgpu::ShaderModuleDescriptor {
@@ -1143,6 +1168,14 @@ impl WgpuCompositor {
multiview_mask: None,
cache: None,
});
+ if let Some(error) = pollster::block_on(scope.pop()) {
+ log::error!(
+ "pass {}: the driver refused its pipeline: {error}",
+ pass.key
+ );
+ self.refused.insert(pass.key.clone());
+ return;
+ }
let frame = self.device.create_buffer(&wgpu::BufferDescriptor {
label: Some("concat pass frame"),
// size(vec2), time, intensity, clip_time, padded to Frame's own
@@ -1186,9 +1219,10 @@ impl WgpuCompositor {
/// seen. Mirrors [`WgpuCompositor::shader`] but binds two input pictures at
/// group 0 and lets the shader own the blend.
fn transition_shader(&mut self, pass: &TransitionPass) {
- if self.transitions.contains_key(&pass.key) {
+ if self.transitions.contains_key(&pass.key) || self.refused.contains(&pass.key) {
return;
}
+ let scope = self.device.push_error_scope(wgpu::ErrorFilter::Validation);
let module = self
.device
.create_shader_module(wgpu::ShaderModuleDescriptor {
@@ -1234,6 +1268,14 @@ impl WgpuCompositor {
multiview_mask: None,
cache: None,
});
+ if let Some(error) = pollster::block_on(scope.pop()) {
+ log::error!(
+ "transition {}: the driver refused its pipeline: {error}",
+ pass.key
+ );
+ self.refused.insert(pass.key.clone());
+ return;
+ }
let frame = self.device.create_buffer(&wgpu::BufferDescriptor {
label: Some("concat transition frame"),
size: 16,
@@ -1454,7 +1496,10 @@ impl WgpuCompositor {
self.shader(pass);
let lut_id = self.lut_group(pass.lut.as_deref());
let reveal_id = self.reveal_group(pass.reveal_map.as_deref());
- let shader = &self.shaders[&pass.key];
+ // A pass the driver refused leaves the picture as it was.
+ let Some(shader) = self.shaders.get(&pass.key) else {
+ continue;
+ };
let lut_group = &self.luts[&lut_id];
let reveal_group = &self.reveals[&reveal_id];
let frame_block: [f32; 6] = [
@@ -1645,6 +1690,9 @@ impl Compositor for WgpuCompositor {
return None;
}
self.transition_shader(pass);
+ if !self.transitions.contains_key(&pass.key) {
+ return None;
+ }
let lut_id = self.lut_group(pass.lut.as_deref());
// The two pictures, uploaded and bound at group 0.
diff --git a/src/crates/concat-render/src/gpu/tests.rs b/src/crates/concat-render/src/gpu/tests.rs
index 4a62a6fc..199a00f1 100644
--- a/src/crates/concat-render/src/gpu/tests.rs
+++ b/src/crates/concat-render/src/gpu/tests.rs
@@ -382,6 +382,32 @@ fn a_benign_package_survives_its_trial() {
assert_eq!(&frame.pixels()[..3], &[0, 0, 255]);
}
+/// A module the driver refuses - here, one that is not WGSL at all, which
+/// only reaches the device because the pass was built by hand rather than
+/// by the catalogue - is caught in its error scope: the layer draws
+/// untreated, the device is not dead, and the trial says no.
+#[test]
+fn a_pass_the_driver_refuses_is_skipped_and_fails_its_trial() {
+ let Some(mut gpu) = gpu() else { return };
+ let mut broken = package("test.broken", INVERT, "", &[], 1.0);
+ broken.key = "test.broken@1#garbage".to_owned();
+ broken.source = Arc::from("this is not a shader");
+ let mut over = layer(solid(4, 4, [0, 200, 0, 255]));
+ over.effects = vec![broken.clone()];
+ let frame = gpu.render(&plan(4, 4, vec![over]));
+ assert_eq!(frame.pixel(1, 1), Some([0, 200, 0, 255]), "drawn untreated");
+ assert!(!gpu.is_dead());
+ assert!(
+ gpu.trial_at(&broken, 64, std::time::Duration::from_secs(5))
+ .is_err()
+ );
+ // And a good pass still runs on the same compositor.
+ let mut over = layer(solid(4, 4, [0, 200, 0, 255]));
+ over.effects = vec![package("test.trial", INVERT, "", &[], 1.0)];
+ let frame = gpu.render(&plan(4, 4, vec![over]));
+ assert_eq!(frame.pixel(1, 1), Some([255, 55, 255, 255]));
+}
+
#[test]
fn output_size_changes_are_handled() {
let Some(mut gpu) = gpu() else { return };
diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rs
index db2f156f..5717f5e2 100644
--- a/src/crates/concat/src/studio.rs
+++ b/src/crates/concat/src/studio.rs
@@ -5468,8 +5468,24 @@ impl Studio {
/// failed. With `announce`, a clean reload is reported too, with the
/// folder, which is how a newcomer learns where packages go.
pub fn reload_packages(&mut self, announce: bool) -> usize {
+ /// A custom package's shader runs once over a picture this many
+ /// pixels a side before the package is offered: enough that a loop
+ /// bounded in the thousands per pixel shows, and a real frame's
+ /// worth of work does not.
+ const TRIAL_SIDE: u32 = 512;
+ /// How long that trial may take before the package is refused.
+ const TRIAL_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(3);
let dir = Self::looks_dir(&self.host.dirs);
- let errors = Catalogue::install(&dir);
+ let monitor = &self.host.monitor;
+ let errors = Catalogue::install_with(&dir, &mut |package| {
+ let Some(pass) = package.trial_pass() else {
+ return Ok(());
+ };
+ match monitor.trial(&pass, TRIAL_SIDE, TRIAL_TIMEOUT) {
+ Some(Err(why)) => Err(format!("its shader failed its trial: {why}")),
+ _ => Ok(()),
+ }
+ });
for error in &errors {
log::warn!("package: {error}");
}