From 7041babc9e5333d01191f3eb80fd711bd26cd4f7 Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 17 Feb 2026 08:46:01 +0100 Subject: feat: add time-based effect activation with auto-passthrough Effects now accept start/end time parameters and automatically passthrough when inactive. Implements buffer chain integrity via compile-time validation. - Effect base class: dispatch_render() checks time bounds, auto-passthroughs 1:1 input/output effects outside [start, end] interval - seq_compiler.py: validates producer/consumer lifespan constraints for multi-output effects, adds --validate flag, always validates before codegen - Updated all 9 effect classes and test fixtures to pass start/end times - check_all.sh: includes timeline validation step - Tests: 34/34 passing, demo runs successfully Co-Authored-By: Claude Sonnet 4.5 --- src/gpu/effect.cc | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) (limited to 'src/gpu/effect.cc') diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc index b729321..117ede2 100644 --- a/src/gpu/effect.cc +++ b/src/gpu/effect.cc @@ -1,11 +1,64 @@ // Effect implementation #include "gpu/effect.h" +#include "gpu/gpu.h" +#include "gpu/sequence.h" #include "util/fatal_error.h" Effect::Effect(const GpuContext& ctx, const std::vector& inputs, - const std::vector& outputs) - : ctx_(ctx), input_nodes_(inputs), output_nodes_(outputs) { + const std::vector& outputs, float start_time, + float end_time) + : ctx_(ctx), input_nodes_(inputs), output_nodes_(outputs), + start_time_(start_time), end_time_(end_time) { FATAL_CHECK(!inputs.empty(), "Effect must have at least one input\n"); FATAL_CHECK(!outputs.empty(), "Effect must have at least one output\n"); + FATAL_CHECK(start_time <= end_time, "Invalid time range: %f > %f\n", + start_time, end_time); +} + +void Effect::dispatch_render(WGPUCommandEncoder encoder, + const UniformsSequenceParams& params, + NodeRegistry& nodes) { + // Check if effect is active at current time + const bool active = + (params.time >= start_time_ && params.time < end_time_); + + // Auto-passthrough for 1:1 input/output effects outside active range + if (!active && input_nodes_.size() == 1 && output_nodes_.size() == 1) { + blit_input_to_output(encoder, nodes); + } else if (active) { + render(encoder, params, nodes); + } + // Multi-output effects: output undefined when inactive (validated at compile time) +} + +void Effect::blit_input_to_output(WGPUCommandEncoder encoder, + NodeRegistry& nodes) { + HEADLESS_RETURN_IF_NULL(encoder); + + WGPUTexture src = nodes.get_texture(input_nodes_[0]); + WGPUTexture dst = nodes.get_texture(output_nodes_[0]); + + // Skip passthrough if textures are external (source/sink) or invalid + if (!src || !dst) { + return; + } + +#if defined(DEMO_CROSS_COMPILE_WIN32) + WGPUImageCopyTexture src_copy = { + .texture = src, .mipLevel = 0, .origin = {0, 0, 0}}; + WGPUImageCopyTexture dst_copy = { + .texture = dst, .mipLevel = 0, .origin = {0, 0, 0}}; +#else + WGPUTexelCopyTextureInfo src_copy = { + .texture = src, .mipLevel = 0, .origin = {0, 0, 0}}; + WGPUTexelCopyTextureInfo dst_copy = { + .texture = dst, .mipLevel = 0, .origin = {0, 0, 0}}; +#endif + + WGPUExtent3D extent = {static_cast(width_), + static_cast(height_), 1}; + + wgpuCommandEncoderCopyTextureToTexture(encoder, &src_copy, &dst_copy, + &extent); } -- cgit v1.2.3