]> git.sesse.net Git - movit/blob - effect_chain.h
Fix more confusion with strong one-to-one effects and compute shaders.
[movit] / effect_chain.h
1 #ifndef _MOVIT_EFFECT_CHAIN_H
2 #define _MOVIT_EFFECT_CHAIN_H 1
3
4 // An EffectChain is the largest basic entity in Movit; it contains everything
5 // needed to connects a series of effects, from inputs to outputs, and render
6 // them. Generally you set up your effect chain once and then call its render
7 // functions once per frame; setting one up can be relatively expensive,
8 // but rendering is fast.
9 //
10 // Threading considerations: EffectChain is “thread-compatible”; you can use
11 // different EffectChains in multiple threads at the same time (assuming the
12 // threads do not use the same OpenGL context, but this is a good idea anyway),
13 // but you may not use one EffectChain from multiple threads simultaneously.
14 // You _are_ allowed to use one EffectChain from multiple threads as long as
15 // you only use it from one at a time (possibly by doing your own locking),
16 // but if so, the threads' contexts need to be set up to share resources, since
17 // the EffectChain holds textures and other OpenGL objects that are tied to the
18 // context.
19 //
20 // Memory management (only relevant if you use multiple contexts):
21 // See corresponding comment in resource_pool.h. This holds even if you don't
22 // allocate your own ResourcePool, but let EffectChain hold its own.
23
24 #include <epoxy/gl.h>
25 #include <stdio.h>
26 #include <list>
27 #include <map>
28 #include <set>
29 #include <string>
30 #include <vector>
31 #include <Eigen/Core>
32
33 #include "effect.h"
34 #include "image_format.h"
35 #include "ycbcr.h"
36
37 namespace movit {
38
39 class Effect;
40 class Input;
41 struct Phase;
42 class ResourcePool;
43
44 // For internal use within Node.
45 enum AlphaType {
46         ALPHA_INVALID = -1,
47         ALPHA_BLANK,
48         ALPHA_PREMULTIPLIED,
49         ALPHA_POSTMULTIPLIED,
50 };
51
52 // Whether you want pre- or postmultiplied alpha in the output
53 // (see effect.h for a discussion of pre- versus postmultiplied alpha).
54 enum OutputAlphaFormat {
55         OUTPUT_ALPHA_FORMAT_PREMULTIPLIED,
56         OUTPUT_ALPHA_FORMAT_POSTMULTIPLIED,
57 };
58
59 // RGBA output is nearly always packed; Y'CbCr, however, is often planar
60 // due to chroma subsampling. This enum controls how add_ycbcr_output()
61 // distributes the color channels between the fragment shader outputs.
62 // Obviously, anything except YCBCR_OUTPUT_INTERLEAVED will be meaningless
63 // unless you use render_to_fbo() and have an FBO with multiple render
64 // targets attached (the other outputs will be discarded).
65 enum YCbCrOutputSplitting {
66         // Only one output: Store Y'CbCr into the first three output channels,
67         // respectively, plus alpha. This is also called “chunked” or
68         // ”packed” mode.
69         YCBCR_OUTPUT_INTERLEAVED,
70
71         // Store Y' and alpha into the first output (in the red and alpha
72         // channels; effect to the others is undefined), and Cb and Cr into
73         // the first two channels of the second output. This is particularly
74         // useful if you want to end up in a format like NV12, where all the
75         // Y' samples come first and then Cb and Cr come interlevaed afterwards.
76         // You will still need to do the chroma subsampling yourself to actually
77         // get down to NV12, though.
78         YCBCR_OUTPUT_SPLIT_Y_AND_CBCR,
79
80         // Store Y' and alpha into the first output, Cb into the first channel
81         // of the second output and Cr into the first channel of the third output.
82         // (Effect on the other channels is undefined.) Essentially gives you
83         // 4:4:4 planar, or ”yuv444p”.
84         YCBCR_OUTPUT_PLANAR,
85 };
86
87 // Where (0,0) is taken to be in the output. If you want to render to an
88 // OpenGL screen, you should keep the default of bottom-left, as that is
89 // OpenGL's natural coordinate system. However, there are cases, such as if you
90 // render to an FBO and read the pixels back into some other system, where
91 // you'd want a top-left origin; if so, an additional flip step will be added
92 // at the very end (but done in a vertex shader, so it will have zero extra
93 // cost).
94 //
95 // Note that Movit's coordinate system in general consistently puts (0,0) in
96 // the top left for _input_, no matter what you set as output origin.
97 enum OutputOrigin {
98         OUTPUT_ORIGIN_BOTTOM_LEFT,
99         OUTPUT_ORIGIN_TOP_LEFT,
100 };
101
102 // Transformation to apply (if any) to pixel data in temporary buffers.
103 // See set_intermediate_format() below for more information.
104 enum FramebufferTransformation {
105         // The default; just store the value. This is what you usually want.
106         NO_FRAMEBUFFER_TRANSFORMATION,
107
108         // If the values are in linear light, store sqrt(x) to the framebuffer
109         // instead of x itself, of course undoing it with x² on read. Useful as
110         // a rough approximation to the sRGB curve. (If the values are not in
111         // linear light, just store them as-is.)
112         SQUARE_ROOT_FRAMEBUFFER_TRANSFORMATION,
113 };
114
115 // Whether a link is into another phase or not; see Node::incoming_link_type.
116 enum NodeLinkType {
117         IN_ANOTHER_PHASE,
118         IN_SAME_PHASE
119 };
120
121 // A node in the graph; basically an effect and some associated information.
122 class Node {
123 public:
124         Effect *effect;
125         bool disabled;
126
127         // Edges in the graph (forward and backward).
128         std::vector<Node *> outgoing_links;
129         std::vector<Node *> incoming_links;
130
131         // For unit tests only. Do not use from other code.
132         // Will contain an arbitrary choice if the node is in multiple phases.
133         Phase *containing_phase;
134
135 private:
136         // Logical size of the output of this effect, ie. the resolution
137         // you would get if you sampled it as a texture. If it is undefined
138         // (since the inputs differ in resolution), it will be 0x0.
139         // If both this and output_texture_{width,height} are set,
140         // they will be equal.
141         unsigned output_width, output_height;
142
143         // If the effect has is_single_texture(), or if the output went to RTT
144         // and that texture has been bound to a sampler, the sampler number
145         // will be stored here.
146         //
147         // TODO: Can an RTT texture be used as inputs to multiple effects
148         // within the same phase? If so, we have a problem with modifying
149         // sampler state here.
150         int bound_sampler_num;
151
152         // For each node in incoming_links, whether it comes from another phase
153         // or not. This is required because in some rather obscure cases,
154         // it is possible to have an input twice in the same phase; both by
155         // itself and as a bounced input.
156         //
157         // TODO: It is possible that we might even need to bounce multiple
158         // times and thus disambiguate also between different external phases,
159         // but we'll deal with that when we need to care about it, if ever.
160         std::vector<NodeLinkType> incoming_link_type;
161
162         // Used during the building of the effect chain.
163         Colorspace output_color_space;
164         GammaCurve output_gamma_curve;
165         AlphaType output_alpha_type;
166         Effect::MipmapRequirements needs_mipmaps;  // Directly or indirectly.
167
168         // Set if this effect, and all effects consuming output from this node
169         // (in the same phase) have one_to_one_sampling() set.
170         bool one_to_one_sampling;
171
172         // Same, for strong_one_to_one_sampling().
173         bool strong_one_to_one_sampling;
174
175         friend class EffectChain;
176 };
177
178 // A rendering phase; a single GLSL program rendering a single quad.
179 struct Phase {
180         Node *output_node;
181
182         GLuint glsl_program_num;  // Owned by the resource_pool.
183
184         // Position and texcoord attribute indexes, although it doesn't matter
185         // which is which, because they contain the same data.
186         std::set<GLint> attribute_indexes;
187
188         // Inputs are only inputs from other phases (ie., those that come from RTT);
189         // input textures are counted as part of <effects>.
190         std::vector<Phase *> inputs;
191         // Bound sampler numbers for each input. Redundant in a sense
192         // (it always corresponds to the index), but we need somewhere
193         // to hold the value for the uniform.
194         std::vector<int> input_samplers;
195         std::vector<Node *> effects;  // In order.
196         unsigned output_width, output_height, virtual_output_width, virtual_output_height;
197
198         // Whether this phase is compiled as a compute shader, ie., the last effect is
199         // marked as one.
200         bool is_compute_shader;
201         Node *compute_shader_node;
202
203         // If <is_compute_shader>, which image unit the output buffer is bound to.
204         // This is used as source for a Uniform<int> below.
205         int outbuf_image_unit;
206
207         // These are used in transforming from unnormalized to normalized coordinates
208         // in compute shaders.
209         int uniform_output_size[2];
210         Point2D inv_output_size, output_texcoord_adjust;
211
212         // Identifier used to create unique variables in GLSL.
213         // Unique per-phase to increase cacheability of compiled shaders.
214         std::map<std::pair<Node *, NodeLinkType>, std::string> effect_ids;
215
216         // Uniforms for this phase; combined from all the effects.
217         std::vector<Uniform<int>> uniforms_image2d;
218         std::vector<Uniform<int>> uniforms_sampler2d;
219         std::vector<Uniform<bool>> uniforms_bool;
220         std::vector<Uniform<int>> uniforms_int;
221         std::vector<Uniform<int>> uniforms_ivec2;
222         std::vector<Uniform<float>> uniforms_float;
223         std::vector<Uniform<float>> uniforms_vec2;
224         std::vector<Uniform<float>> uniforms_vec3;
225         std::vector<Uniform<float>> uniforms_vec4;
226         std::vector<Uniform<Eigen::Matrix3d>> uniforms_mat3;
227
228         // For measurement of GPU time used.
229         std::list<GLuint> timer_query_objects_running;
230         std::list<GLuint> timer_query_objects_free;
231         uint64_t time_elapsed_ns;
232         uint64_t num_measured_iterations;
233 };
234
235 class EffectChain {
236 public:
237         // Aspect: e.g. 16.0f, 9.0f for 16:9.
238         // resource_pool is a pointer to a ResourcePool with which to share shaders
239         // and other resources (see resource_pool.h). If nullptr (the default),
240         // will create its own that is not shared with anything else. Does not take
241         // ownership of the passed-in ResourcePool, but will naturally take ownership
242         // of its own internal one if created.
243         EffectChain(float aspect_nom, float aspect_denom, ResourcePool *resource_pool = nullptr);
244         ~EffectChain();
245
246         // User API:
247         // input, effects, output, finalize need to come in that specific order.
248
249         // EffectChain takes ownership of the given input.
250         // input is returned back for convenience.
251         Input *add_input(Input *input);
252
253         // EffectChain takes ownership of the given effect.
254         // effect is returned back for convenience.
255         Effect *add_effect(Effect *effect) {
256                 return add_effect(effect, last_added_effect());
257         }
258         Effect *add_effect(Effect *effect, Effect *input) {
259                 std::vector<Effect *> inputs;
260                 inputs.push_back(input);
261                 return add_effect(effect, inputs);
262         }
263         Effect *add_effect(Effect *effect, Effect *input1, Effect *input2) {
264                 std::vector<Effect *> inputs;
265                 inputs.push_back(input1);
266                 inputs.push_back(input2);
267                 return add_effect(effect, inputs);
268         }
269         Effect *add_effect(Effect *effect, Effect *input1, Effect *input2, Effect *input3) {
270                 std::vector<Effect *> inputs;
271                 inputs.push_back(input1);
272                 inputs.push_back(input2);
273                 inputs.push_back(input3);
274                 return add_effect(effect, inputs);
275         }
276         Effect *add_effect(Effect *effect, Effect *input1, Effect *input2, Effect *input3, Effect *input4) {
277                 std::vector<Effect *> inputs;
278                 inputs.push_back(input1);
279                 inputs.push_back(input2);
280                 inputs.push_back(input3);
281                 inputs.push_back(input4);
282                 return add_effect(effect, inputs);
283         }
284         Effect *add_effect(Effect *effect, Effect *input1, Effect *input2, Effect *input3, Effect *input4, Effect *input5) {
285                 std::vector<Effect *> inputs;
286                 inputs.push_back(input1);
287                 inputs.push_back(input2);
288                 inputs.push_back(input3);
289                 inputs.push_back(input4);
290                 inputs.push_back(input5);
291                 return add_effect(effect, inputs);
292         }
293         Effect *add_effect(Effect *effect, const std::vector<Effect *> &inputs);
294
295         // Adds an RGBA output. Note that you can have at most one RGBA output and two
296         // Y'CbCr outputs (see below for details).
297         void add_output(const ImageFormat &format, OutputAlphaFormat alpha_format);
298
299         // Adds an YCbCr output. Note that you can only have at most two Y'CbCr
300         // outputs, and they must have the same <ycbcr_format> and <type>.
301         // (This limitation may be lifted in the future, to allow e.g. simultaneous
302         // 8- and 10-bit output. Currently, multiple Y'CbCr outputs are only
303         // useful in some very limited circumstances, like if one texture goes
304         // to some place you cannot easily read from later.)
305         //
306         // Only 4:4:4 output is supported due to fragment shader limitations,
307         // so chroma_subsampling_x and chroma_subsampling_y must both be 1.
308         // <type> should match the data type of the FBO you are rendering to,
309         // so that if you use 16-bit output (GL_UNSIGNED_SHORT), you will get
310         // 8-, 10- or 12-bit output correctly as determined by <ycbcr_format.num_levels>.
311         // Using e.g. ycbcr_format.num_levels == 1024 with GL_UNSIGNED_BYTE is
312         // nonsensical and invokes undefined behavior.
313         //
314         // If you have both RGBA and Y'CbCr output(s), the RGBA output will come
315         // in the last draw buffer. Also, <format> and <alpha_format> must be
316         // identical between the two.
317         void add_ycbcr_output(const ImageFormat &format, OutputAlphaFormat alpha_format,
318                               const YCbCrFormat &ycbcr_format,
319                               YCbCrOutputSplitting output_splitting = YCBCR_OUTPUT_INTERLEAVED,
320                               GLenum output_type = GL_UNSIGNED_BYTE);
321
322         // Change Y'CbCr output format. (This can be done also after finalize()).
323         // Note that you are not allowed to change subsampling parameters;
324         // however, you can change the color space parameters, ie.,
325         // luma_coefficients, full_range and num_levels.
326         void change_ycbcr_output_format(const YCbCrFormat &ycbcr_format);
327
328         // Set number of output bits, to scale the dither.
329         // 8 is the right value for most outputs.
330         //
331         // Special note for 10- and 12-bit Y'CbCr packed into GL_UNSIGNED_SHORT:
332         // This is relative to the actual output, not the logical one, so you should
333         // specify 16 here, not 10 or 12.
334         //
335         // The default, 0, is a special value that means no dither.
336         void set_dither_bits(unsigned num_bits)
337         {
338                 this->num_dither_bits = num_bits;
339         }
340
341         // Set where (0,0) is taken to be in the output. The default is
342         // OUTPUT_ORIGIN_BOTTOM_LEFT, which is usually what you want
343         // (see OutputOrigin above for more details).
344         void set_output_origin(OutputOrigin output_origin)
345         {
346                 this->output_origin = output_origin;
347         }
348
349         // Set intermediate format for framebuffers used when we need to bounce
350         // to a temporary texture. The default, GL_RGBA16F, is good for most uses;
351         // it is precise, has good range, and is relatively efficient. However,
352         // if you need even more speed and your chain can do with some loss of
353         // accuracy, you can change the format here (before calling finalize).
354         // Calculations between bounce buffers are still in 32-bit floating-point
355         // no matter what you specify.
356         //
357         // Of special interest is GL_SRGB8_ALPHA8, which stores sRGB-encoded RGB
358         // and linear alpha; this is half the memory bandwidth of GL_RGBA16F,
359         // while retaining reasonable precision for typical image data. It will,
360         // however, cause some gamut clipping if your colorspace is far from sRGB,
361         // as it cannot represent values outside [0,1]. NOTE: If you construct
362         // a chain where you end up bouncing pixels in non-linear light
363         // (gamma different from GAMMA_LINEAR), this will be the wrong thing.
364         // However, it's hard to see how this could happen in a non-contrived
365         // chain; few effects ever need texture bounce or resizing without also
366         // combining multiple pixels, which really needs linear light and thus
367         // triggers a conversion before the bounce.
368         //
369         // If you don't need alpha (or can do with very little of it), GL_RGB10_A2
370         // is even better, as it has two more bits for each color component. There
371         // is no GL_SRGB10, unfortunately, so on its own, it is somewhat worse than
372         // GL_SRGB8, but you can set <transformation> to SQUARE_ROOT_FRAMEBUFFER_TRANSFORMATION,
373         // and sqrt(x) will be stored instead of x. This is a rough approximation to
374         // the sRGB curve, and reduces maximum error (in sRGB distance) by almost an
375         // order of magnitude, well below what you can get from 8-bit true sRGB.
376         // (Note that this strategy avoids the problem with bounced non-linear data
377         // above, since the square root is turned off in that case.) However, texture
378         // filtering will happen on the transformed values, so if you have heavy
379         // downscaling or the likes (e.g. mipmaps), you could get subtly bad results.
380         // You'll need to see which of the two that works the best for you in practice.
381         void set_intermediate_format(
382                 GLenum intermediate_format,
383                 FramebufferTransformation transformation = NO_FRAMEBUFFER_TRANSFORMATION)
384         {
385                 this->intermediate_format = intermediate_format;
386                 this->intermediate_transformation = transformation;
387         }
388
389         void finalize();
390
391         // Measure the GPU time used for each actual phase during rendering.
392         // Note that this is only available if GL_ARB_timer_query
393         // (or, equivalently, OpenGL 3.3) is available. Also note that measurement
394         // will incur a performance cost, as we wait for the measurements to
395         // complete at the end of rendering.
396         void enable_phase_timing(bool enable);
397         void reset_phase_timing();
398         void print_phase_timing();
399
400         // Note: If you already know the width and height of the viewport,
401         // calling render_to_fbo() directly will be slightly more efficient,
402         // as it saves it from getting it from OpenGL.
403         void render_to_screen()
404         {
405                 render_to_fbo(0, 0, 0);
406         }
407
408         // Render the effect chain to the given FBO. If width=height=0, keeps
409         // the current viewport.
410         void render_to_fbo(GLuint fbo, unsigned width, unsigned height);
411
412         // Render the effect chain to the given set of textures. This is equivalent
413         // to render_to_fbo() with a freshly created FBO bound to the given textures,
414         // except that it is more efficient if the last phase contains a compute shader.
415         // Thus, prefer this to render_to_fbo() where possible.
416         //
417         // Only one destination texture is supported. This restriction will be lifted
418         // in the future.
419         //
420         // All destination textures must be exactly of size <width> x <height>,
421         // and must either come from the same ResourcePool the effect uses, or outlive
422         // the EffectChain (otherwise, we could be allocating FBOs that end up being
423         // stale). Textures must also have valid state; in particular, they must either
424         // be mipmap complete or have a non-mipmapped minification mode.
425         //
426         // width and height can not be zero.
427         struct DestinationTexture {
428                 GLuint texnum;
429                 GLenum format;
430         };
431         void render_to_texture(const std::vector<DestinationTexture> &destinations, unsigned width, unsigned height);
432
433         Effect *last_added_effect() {
434                 if (nodes.empty()) {
435                         return nullptr;
436                 } else {
437                         return nodes.back()->effect;
438                 }       
439         }
440
441         // API for manipulating the graph directly. Intended to be used from
442         // effects and by EffectChain itself.
443         //
444         // Note that for nodes with multiple inputs, the order of calls to
445         // connect_nodes() will matter.
446         Node *add_node(Effect *effect);
447         void connect_nodes(Node *sender, Node *receiver);
448         void replace_receiver(Node *old_receiver, Node *new_receiver);
449         void replace_sender(Node *new_sender, Node *receiver);
450         void insert_node_between(Node *sender, Node *middle, Node *receiver);
451         Node *find_node_for_effect(Effect *effect) { return node_map[effect]; }
452
453         // Get the OpenGL sampler (GL_TEXTURE0, GL_TEXTURE1, etc.) for the
454         // input of the given node, so that one can modify the sampler state
455         // directly. Only valid to call during set_gl_state().
456         //
457         // Also, for this to be allowed, <node>'s effect must have
458         // needs_texture_bounce() set, so that it samples directly from a
459         // single-sampler input, or from an RTT texture.
460         GLenum get_input_sampler(Node *node, unsigned input_num) const;
461
462         // Whether input <input_num> of <node> corresponds to a single sampler
463         // (see get_input_sampler()). Normally, you should not need to call this;
464         // however, if the input Effect has set override_texture_bounce(),
465         // this will return false, and you could be flexible and check it first
466         // if you want.
467         GLenum has_input_sampler(Node *node, unsigned input_num) const;
468
469         // Get the current resource pool assigned to this EffectChain.
470         // Primarily to let effects allocate textures as needed.
471         // Any resources you get from the pool must be returned to the pool
472         // no later than in the Effect's destructor.
473         ResourcePool *get_resource_pool() { return resource_pool; }
474
475 private:
476         // Make sure the output rectangle is at least large enough to hold
477         // the given input rectangle in both dimensions, and is of the
478         // current aspect ratio (aspect_nom/aspect_denom).
479         void size_rectangle_to_fit(unsigned width, unsigned height, unsigned *output_width, unsigned *output_height);
480
481         // Compute the input sizes for all inputs for all effects in a given phase,
482         // and inform the effects about the results.    
483         void inform_input_sizes(Phase *phase);
484
485         // Determine the preferred output size of a given phase.
486         // Requires that all input phases (if any) already have output sizes set.
487         void find_output_size(Phase *phase);
488
489         // Find all inputs eventually feeding into this effect that have
490         // output gamma different from GAMMA_LINEAR.
491         void find_all_nonlinear_inputs(Node *effect, std::vector<Node *> *nonlinear_inputs);
492
493         // Create a GLSL program computing the effects for this phase in order.
494         void compile_glsl_program(Phase *phase);
495
496         // Create all GLSL programs needed to compute the given effect, and all outputs
497         // that depend on it (whenever possible). Returns the phase that has <output>
498         // as the last effect. Also pushes all phases in order onto <phases>.
499         Phase *construct_phase(Node *output, std::map<Node *, Phase *> *completed_effects);
500
501         // Do the actual rendering of the chain. If <dest_fbo> is not (GLuint)-1,
502         // renders to that FBO. If <destinations> is non-empty, render to that set
503         // of textures (last phase, save for the dummy phase, must be a compute shader),
504         // with x/y ignored. Having both set is an error.
505         void render(GLuint dest_fbo, const std::vector<DestinationTexture> &destinations,
506                     unsigned x, unsigned y, unsigned width, unsigned height);
507
508         // Execute one phase, ie. set up all inputs, effects and outputs, and render the quad.
509         // If <destinations> is empty, uses whatever output is current (and the phase must not be
510         // a compute shader).
511         void execute_phase(Phase *phase,
512                            const std::map<Phase *, GLuint> &output_textures,
513                            const std::vector<DestinationTexture> &destinations,
514                            std::set<Phase *> *generated_mipmaps);
515
516         // Set up uniforms for one phase. The program must already be bound.
517         void setup_uniforms(Phase *phase);
518
519         // Set up the given sampler number for sampling from an RTT texture.
520         void setup_rtt_sampler(int sampler_num, bool use_mipmaps);
521
522         // Output the current graph to the given file in a Graphviz-compatible format;
523         // only useful for debugging.
524         void output_dot(const char *filename);
525         std::vector<std::string> get_labels_for_edge(const Node *from, const Node *to);
526         void output_dot_edge(FILE *fp,
527                              const std::string &from_node_id,
528                              const std::string &to_node_id,
529                              const std::vector<std::string> &labels);
530
531         // Some of the graph algorithms assume that the nodes array is sorted
532         // topologically (inputs are always before outputs), but some operations
533         // (like graph rewriting) can change that. This function restores that order.
534         void sort_all_nodes_topologically();
535
536         // Do the actual topological sort. <nodes> must be a connected, acyclic subgraph;
537         // links that go to nodes not in the set will be ignored.
538         std::vector<Node *> topological_sort(const std::vector<Node *> &nodes);
539
540         // Utility function used by topological_sort() to do a depth-first search.
541         // The reason why we store nodes left to visit instead of a more conventional
542         // list of nodes to visit is that we want to be able to limit ourselves to
543         // a subgraph instead of all nodes. The set thus serves a dual purpose.
544         void topological_sort_visit_node(Node *node, std::set<Node *> *nodes_left_to_visit, std::vector<Node *> *sorted_list);
545
546         // Used during finalize().
547         void find_color_spaces_for_inputs();
548         void propagate_alpha();
549         void propagate_gamma_and_color_space();
550         Node *find_output_node();
551
552         bool node_needs_colorspace_fix(Node *node);
553         void fix_internal_color_spaces();
554         void fix_output_color_space();
555
556         bool node_needs_alpha_fix(Node *node);
557         void fix_internal_alpha(unsigned step);
558         void fix_output_alpha();
559
560         bool node_needs_gamma_fix(Node *node);
561         void fix_internal_gamma_by_asking_inputs(unsigned step);
562         void fix_internal_gamma_by_inserting_nodes(unsigned step);
563         void fix_output_gamma();
564         void add_ycbcr_conversion_if_needed();
565         void add_dither_if_needed();
566         void add_dummy_effect_if_needed();
567
568         float aspect_nom, aspect_denom;
569         ImageFormat output_format;
570         OutputAlphaFormat output_alpha_format;
571
572         bool output_color_rgba;
573         int num_output_color_ycbcr;                      // Max 2.
574         YCbCrFormat output_ycbcr_format;                 // If num_output_color_ycbcr is > 0.
575         GLenum output_ycbcr_type;                        // If num_output_color_ycbcr is > 0.
576         YCbCrOutputSplitting output_ycbcr_splitting[2];  // If num_output_color_ycbcr is > N.
577
578         std::vector<Node *> nodes;
579         std::map<Effect *, Node *> node_map;
580         Effect *dither_effect;
581         Node *ycbcr_conversion_effect_node;
582
583         std::vector<Input *> inputs;  // Also contained in nodes.
584         std::vector<Phase *> phases;
585
586         GLenum intermediate_format;
587         FramebufferTransformation intermediate_transformation;
588         unsigned num_dither_bits;
589         OutputOrigin output_origin;
590         bool finalized;
591         GLuint vbo;  // Contains vertex and texture coordinate data.
592
593         // Whether the last effect (which will then be in a phase all by itself)
594         // is a dummy effect that is only added because the last phase uses a compute
595         // shader, which cannot output directly to the backbuffer. This means that
596         // the phase can be skipped if we are _not_ rendering to the backbuffer.
597         bool has_dummy_effect = false;
598
599         ResourcePool *resource_pool;
600         bool owns_resource_pool;
601
602         bool do_phase_timing;
603 };
604
605 }  // namespace movit
606
607 #endif // !defined(_MOVIT_EFFECT_CHAIN_H)