summaryrefslogtreecommitdiff
path: root/src/gpu/effects/cnn_effect.h
blob: bc074d2a944ac38ebeea8a86be607efb30a28f2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// CNN post-processing effect header
// Multi-layer neural network stylization

#pragma once
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"

struct CNNLayerParams {
  int layer_index;
  float blend_amount;  // Blend: mix(input, output, blend_amount)
  float _pad[2];
};
static_assert(sizeof(CNNLayerParams) == 16);

struct CNNEffectParams {
  int layer_index = 0;        // Which layer to render (0-based)
  int total_layers = 1;       // Total number of layers in the CNN
  float blend_amount = 1.0f;  // Final blend with original input
};

class CNNEffect : public PostProcessEffect {
 public:
  explicit CNNEffect(const GpuContext& ctx);
  explicit CNNEffect(const GpuContext& ctx, const CNNEffectParams& params);

  void init(MainSequence* demo) override;
  void render(WGPURenderPassEncoder pass, float time, float beat,
              float intensity, float aspect_ratio) override;
  void update_bind_group(WGPUTextureView input_view) override;

  // Layer 0 needs framebuffer capture for original input
  bool needs_framebuffer_capture() const override {
    return layer_index_ == 0;
  }

 private:
  int layer_index_;
  int total_layers_;
  float blend_amount_;
  WGPUTextureView input_view_;
  WGPUTextureView original_view_;
  UniformBuffer<CNNLayerParams> params_buffer_;
  WGPUBindGroup bind_group_;
  MainSequence* demo_ = nullptr;
};