diff options
Diffstat (limited to 'src/gpu/effect.cc')
| -rw-r--r-- | src/gpu/effect.cc | 57 |
1 files changed, 55 insertions, 2 deletions
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<std::string>& inputs, - const std::vector<std::string>& outputs) - : ctx_(ctx), input_nodes_(inputs), output_nodes_(outputs) { + const std::vector<std::string>& 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<unsigned int>(width_), + static_cast<unsigned int>(height_), 1}; + + wgpuCommandEncoderCopyTextureToTexture(encoder, &src_copy, &dst_copy, + &extent); } |
