Files
test/source/blender/compositor/operations/COM_FileOutputOperation.h
Omar Emara 931c188ce5 Compositor: Refactor File Output node
This patches refactors the compositor File Output mechanism and
implements the file output node for the Realtime Compositor. The
refactor was done for the following reasons:

1. The existing file output mechanism relied on a global EXR image
   resource where the result of each compositor execution for each
   view was accumulated and stored in the global resource, until the
   last view is executed, when the EXR is finally saved. Aside from
   relying on global resources, this can cause effective memory leaks
   since the compositor can be interrupted before the EXR is written and
   closed.
2. We need common code to share between all compositors since we now
   have multiple compositor implementations.
3. We needed to take the opportunity to fix some of the issues with the
   existing implementation, like lossy compression of data passes,
   and inability to save single values passes.

The refactor first introduced a new structure called the Compositor
Render Context. This context stores compositor information related to
the render pipeline and is persistent across all compositor executions
of all views. Its extended lifetime relative to a single compositor
execution lends itself well to store data that is accumulated across
views. The context currently has a map of File Output objects. Those
objects wrap a Render Result structure and can be used to construct
multi-view images which can then be saved after all views are executed
using the existing BKE_image_render_write function.

Minor adjustments were made to the BKE and RE modules to allow saving
using the BKE_image_render_write function. Namely, the function now
allows the use of a source image format for saving as well as the
ability to not save the render result as a render by introducing two new
default arguments. Further, for multi-layer EXR saving, the existent of
a single unnamed render layer will omit the layer name from the EXR
channel full name, and only the pass, view, and channel ID will remain.
Finally, the Render Result to Image Buffer conversion now take he number
of channels into account, instead of always assuming color channels.

The patch implements the File Output node in the Realtime Compositor
using the aforementioned mechanisms, replaces the implementation of the
CPU compositor using the same Realtime Compositor implementation, and
setup the necessary logic in the render pipeline code.

Pull Request: https://projects.blender.org/blender/blender/pulls/113982
2023-12-13 11:08:03 +01:00

107 lines
3.6 KiB
C++

/* SPDX-FileCopyrightText: 2011 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "BLI_vector.hh"
#include "DNA_node_types.h"
#include "COM_CompositorContext.h"
#include "COM_MultiThreadedOperation.h"
struct StampData;
namespace blender::realtime_compositor {
class FileOutput;
}
namespace blender::compositor {
struct FileOutputInput {
FileOutputInput(NodeImageMultiFileSocket *data, DataType data_type);
NodeImageMultiFileSocket *data;
DataType data_type;
float *output_buffer = nullptr;
SocketReader *image_input = nullptr;
};
class FileOutputOperation : public MultiThreadedOperation {
private:
const CompositorContext *context_;
const NodeImageMultiFile *node_data_;
Vector<FileOutputInput> file_output_inputs_;
public:
FileOutputOperation(const CompositorContext *context,
const NodeImageMultiFile *node_data,
Vector<FileOutputInput> inputs);
void execute_region(rcti *rect, unsigned int tile_number) override;
bool is_output_operation(bool /*rendering*/) const override
{
return true;
}
void init_execution() override;
void deinit_execution() override;
eCompositorPriority get_render_priority() const override
{
return eCompositorPriority::Low;
}
void update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> inputs) override;
private:
void execute_single_layer();
void execute_single_layer_multi_view_exr(const FileOutputInput &input,
const ImageFormatData &format,
const char *base_path);
void execute_multi_layer();
/* Add a pass of the given name, view, and input buffer. The pass channel identifiers follows the
* EXR conventions. */
void add_pass_for_input(realtime_compositor::FileOutput &file_output,
const FileOutputInput &input,
const char *pass_name,
const char *view_name);
/* Add a view of the given name and input buffer. */
void add_view_for_input(realtime_compositor::FileOutput &file_output,
const FileOutputInput &input,
const char *view_name);
/* Get the base path of the image to be saved, based on the base path of the node. The base name
* is an optional initial name of the image, which will later be concatenated with other
* information like the frame number, view, and extension. If the base name is empty, then the
* base path represents a directory, so a trailing slash is ensured. */
void get_single_layer_image_base_path(const char *base_name, char *base_path);
/* Get the path of the image to be saved based on the given format. */
void get_single_layer_image_path(const char *base_path,
const ImageFormatData &format,
char *image_path);
/* Get the path of the EXR image to be saved. If the given view is not empty, its corresponding
* file suffix will be appended to the name. */
void get_multi_layer_exr_image_path(const char *base_path, const char *view, char *image_path);
bool is_multi_layer();
const char *get_base_path();
/* Add the file format extensions to the rendered file name. */
bool use_file_extension();
/* If true, save views in a multi-view EXR file, otherwise, save each view in its own file. */
bool is_multi_view_exr();
bool is_multi_view_scene();
};
} // namespace blender::compositor