From f99ad333a7acbb6c8c995dbb036484ae8940c490 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 8 Oct 2012 14:45:32 +0200 Subject: [PATCH] Output the graph in dot form at finalize time. --- blur_effect.h | 4 ++++ colorspace_conversion_effect.h | 1 + diffusion_effect.h | 2 ++ effect.h | 7 ++++++- effect_chain.cpp | 22 ++++++++++++++++++++++ effect_chain.h | 4 ++++ flat_input.h | 2 ++ gamma_compression_effect.h | 1 + gamma_expansion_effect.h | 1 + glow_effect.h | 1 + lift_gamma_gain_effect.h | 1 + mirror_effect.h | 1 + mix_effect.h | 1 + resize_effect.h | 1 + sandbox_effect.h | 1 + saturation_effect.h | 1 + vignette_effect.h | 1 + ycbcr_input.h | 2 ++ 18 files changed, 53 insertions(+), 1 deletion(-) diff --git a/blur_effect.h b/blur_effect.h index 9bacd53..788d337 100644 --- a/blur_effect.h +++ b/blur_effect.h @@ -17,6 +17,8 @@ class BlurEffect : public Effect { public: BlurEffect(); + virtual std::string effect_type_id() const { return "BlurEffect"; } + // We want this for the same reason as ResizeEffect; we could end up scaling // down quite a lot. virtual bool needs_texture_bounce() const { return true; } @@ -43,6 +45,8 @@ private: class SingleBlurPassEffect : public Effect { public: SingleBlurPassEffect(); + virtual std::string effect_type_id() const { return "SingleBlurPassEffect"; } + std::string output_fragment_shader(); virtual bool needs_texture_bounce() const { return true; } diff --git a/colorspace_conversion_effect.h b/colorspace_conversion_effect.h index e3c60ea..1e7bd5b 100644 --- a/colorspace_conversion_effect.h +++ b/colorspace_conversion_effect.h @@ -14,6 +14,7 @@ class ColorSpaceConversionEffect : public Effect { public: ColorSpaceConversionEffect(); + virtual std::string effect_type_id() const { return "ColorSpaceConversionEffect"; } std::string output_fragment_shader(); virtual bool needs_srgb_primaries() const { return false; } diff --git a/diffusion_effect.h b/diffusion_effect.h index bda2649..f8ed77c 100644 --- a/diffusion_effect.h +++ b/diffusion_effect.h @@ -20,6 +20,7 @@ class OverlayMatteEffect; class DiffusionEffect : public Effect { public: DiffusionEffect(); + virtual std::string effect_type_id() const { return "DiffusionEffect"; } virtual void add_self_to_effect_chain(EffectChain *chain, const std::vector &input); virtual bool set_float(const std::string &key, float value); @@ -41,6 +42,7 @@ private: class OverlayMatteEffect : public Effect { public: OverlayMatteEffect(); + virtual std::string effect_type_id() const { return "OverlayMatteEffect"; } std::string output_fragment_shader(); unsigned num_inputs() const { return 2; } diff --git a/effect.h b/effect.h index c016a55..f1520b7 100644 --- a/effect.h +++ b/effect.h @@ -46,7 +46,12 @@ void set_uniform_vec3(GLuint glsl_program_num, const std::string &prefix, const void set_uniform_vec4_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values); class Effect { -public: +public: + // An identifier for this type of effect, mostly used for debug output + // (but some special names, like "ColorSpaceConversionEffect", holds special + // meaning). Same as the class name is fine. + virtual std::string effect_type_id() const = 0; + // Whether this effects expects its input (and output) to be in // linear gamma, ie. without an applied gamma curve. Most effects // will want this, although the ones that never actually look at diff --git a/effect_chain.cpp b/effect_chain.cpp index 1d84e89..4f1900d 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -414,6 +414,26 @@ void EffectChain::construct_glsl_programs(Node *output) std::reverse(phases.begin(), phases.end()); } +void EffectChain::output_dot(const char *filename) +{ + FILE *fp = fopen(filename, "w"); + if (fp == NULL) { + perror(filename); + exit(1); + } + + fprintf(fp, "digraph G {\n"); + for (unsigned i = 0; i < nodes.size(); ++i) { + fprintf(fp, " n%ld [label=\"%s\"];\n", (long)nodes[i], nodes[i]->effect->effect_type_id().c_str()); + for (unsigned j = 0; j < nodes[i]->outgoing_links.size(); ++j) { + fprintf(fp, " n%ld -> n%ld;\n", (long)nodes[i], (long)nodes[i]->outgoing_links[j]); + } + } + fprintf(fp, "}\n"); + + fclose(fp); +} + void EffectChain::find_output_size(Phase *phase) { Node *output_node = phase->effects.back(); @@ -453,6 +473,8 @@ void EffectChain::find_output_size(Phase *phase) void EffectChain::finalize() { + output_dot("final.dot"); + // Find the output effect. This is, simply, one that has no outgoing links. // If there are multiple ones, the graph is malformed (we do not support // multiple outputs right now). diff --git a/effect_chain.h b/effect_chain.h index 6aa5b48..0abd518 100644 --- a/effect_chain.h +++ b/effect_chain.h @@ -123,6 +123,10 @@ private: // that depends on it (whenever possible). void construct_glsl_programs(Node *output); + // Output the current graph to the given file in a Graphviz-compatible format; + // only useful for debugging. + void output_dot(const char *filename); + unsigned width, height; ImageFormat output_format; diff --git a/flat_input.h b/flat_input.h index 9266659..3bcdc76 100644 --- a/flat_input.h +++ b/flat_input.h @@ -9,6 +9,8 @@ class FlatInput : public Input { public: FlatInput(ImageFormat format, MovitPixelFormat pixel_format, unsigned width, unsigned height); + virtual std::string effect_type_id() const { return "FlatInput"; } + // Create the texture itself. We cannot do this in the constructor, // because we don't necessarily know all the settings (sRGB texture, // mipmap generation) at that point. diff --git a/gamma_compression_effect.h b/gamma_compression_effect.h index 4c77b4c..03cbb24 100644 --- a/gamma_compression_effect.h +++ b/gamma_compression_effect.h @@ -15,6 +15,7 @@ class GammaCompressionEffect : public Effect { public: GammaCompressionEffect(); + virtual std::string effect_type_id() const { return "GammaCompressionEffect"; } std::string output_fragment_shader(); virtual bool needs_srgb_primaries() const { return false; } diff --git a/gamma_expansion_effect.h b/gamma_expansion_effect.h index 7992617..b93848a 100644 --- a/gamma_expansion_effect.h +++ b/gamma_expansion_effect.h @@ -15,6 +15,7 @@ class GammaExpansionEffect : public Effect { public: GammaExpansionEffect(); + virtual std::string effect_type_id() const { return "GammaExpansionEffect"; } std::string output_fragment_shader(); virtual bool needs_linear_light() const { return false; } diff --git a/glow_effect.h b/glow_effect.h index 7ee164d..1b5644b 100644 --- a/glow_effect.h +++ b/glow_effect.h @@ -11,6 +11,7 @@ class MixEffect; class GlowEffect : public Effect { public: GlowEffect(); + virtual std::string effect_type_id() const { return "GlowEffect"; } virtual bool needs_srgb_primaries() const { return false; } diff --git a/lift_gamma_gain_effect.h b/lift_gamma_gain_effect.h index 533a7b2..1319570 100644 --- a/lift_gamma_gain_effect.h +++ b/lift_gamma_gain_effect.h @@ -22,6 +22,7 @@ class LiftGammaGainEffect : public Effect { public: LiftGammaGainEffect(); + virtual std::string effect_type_id() const { return "LiftGammaGainEffect"; } std::string output_fragment_shader(); void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num); diff --git a/mirror_effect.h b/mirror_effect.h index 343eb17..0e8dd7b 100644 --- a/mirror_effect.h +++ b/mirror_effect.h @@ -8,6 +8,7 @@ class MirrorEffect : public Effect { public: MirrorEffect(); + virtual std::string effect_type_id() const { return "MirrorEffect"; } std::string output_fragment_shader(); virtual bool needs_linear_light() const { return false; } diff --git a/mix_effect.h b/mix_effect.h index 7342b90..8032062 100644 --- a/mix_effect.h +++ b/mix_effect.h @@ -8,6 +8,7 @@ class MixEffect : public Effect { public: MixEffect(); + virtual std::string effect_type_id() const { return "MixEffect"; } std::string output_fragment_shader(); virtual bool needs_srgb_primaries() const { return false; } diff --git a/resize_effect.h b/resize_effect.h index 54c2b31..4c3fe86 100644 --- a/resize_effect.h +++ b/resize_effect.h @@ -10,6 +10,7 @@ class ResizeEffect : public Effect { public: ResizeEffect(); + virtual std::string effect_type_id() const { return "ResizeEffect"; } std::string output_fragment_shader(); // We want processing done pre-filtering and mipmapped, diff --git a/sandbox_effect.h b/sandbox_effect.h index 44e8d3f..4443ff7 100644 --- a/sandbox_effect.h +++ b/sandbox_effect.h @@ -13,6 +13,7 @@ class SandboxEffect : public Effect { public: SandboxEffect(); + virtual std::string effect_type_id() const { return "SandboxEffect"; } std::string output_fragment_shader(); void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num); diff --git a/saturation_effect.h b/saturation_effect.h index 180210c..4dd72e4 100644 --- a/saturation_effect.h +++ b/saturation_effect.h @@ -12,6 +12,7 @@ class SaturationEffect : public Effect { public: SaturationEffect(); + virtual std::string effect_type_id() const { return "SaturationEffect"; } std::string output_fragment_shader(); private: diff --git a/vignette_effect.h b/vignette_effect.h index d7c66f6..b8634fc 100644 --- a/vignette_effect.h +++ b/vignette_effect.h @@ -9,6 +9,7 @@ class VignetteEffect : public Effect { public: VignetteEffect(); + virtual std::string effect_type_id() const { return "VignetteEffect"; } std::string output_fragment_shader(); virtual bool needs_srgb_primaries() const { return false; } diff --git a/ycbcr_input.h b/ycbcr_input.h index d4cdf9f..43d1f1d 100644 --- a/ycbcr_input.h +++ b/ycbcr_input.h @@ -31,6 +31,8 @@ public: const YCbCrFormat &ycbcr_format, unsigned width, unsigned height); + virtual std::string effect_type_id() const { return "YCbCrInput"; } + // Create the texture itself. We cannot do this in the constructor, // because we don't necessarily know all the settings (sRGB texture, // mipmap generation) at that point. -- 2.39.2