2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2022-08-10 09:14:22 +02:00
|
|
|
|
2023-06-21 05:41:49 +02:00
|
|
|
#include "BLI_assert.h"
|
2022-08-10 09:14:22 +02:00
|
|
|
#include "BLI_string_ref.hh"
|
2024-05-28 08:13:46 +02:00
|
|
|
#include "BLI_timeit.hh"
|
2023-06-21 05:41:49 +02:00
|
|
|
|
2022-08-10 09:14:22 +02:00
|
|
|
#include "DNA_node_types.h"
|
|
|
|
|
|
|
|
|
|
#include "NOD_derived_node_tree.hh"
|
|
|
|
|
|
2024-02-19 15:26:10 +01:00
|
|
|
#include "BKE_node.hh"
|
2023-06-21 05:41:49 +02:00
|
|
|
|
2024-10-10 18:28:34 +03:00
|
|
|
#include "COM_algorithm_compute_preview.hh"
|
2022-08-10 09:14:22 +02:00
|
|
|
#include "COM_context.hh"
|
|
|
|
|
#include "COM_input_descriptor.hh"
|
|
|
|
|
#include "COM_node_operation.hh"
|
|
|
|
|
#include "COM_operation.hh"
|
|
|
|
|
#include "COM_result.hh"
|
|
|
|
|
#include "COM_scheduler.hh"
|
|
|
|
|
#include "COM_utilities.hh"
|
|
|
|
|
|
2024-12-17 11:39:04 +01:00
|
|
|
namespace blender::compositor {
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
using namespace nodes::derived_node_tree_types;
|
|
|
|
|
|
|
|
|
|
NodeOperation::NodeOperation(Context &context, DNode node) : Operation(context), node_(node)
|
|
|
|
|
{
|
2022-08-31 12:15:57 +02:00
|
|
|
for (const bNodeSocket *output : node->output_sockets()) {
|
2025-03-24 10:00:52 +02:00
|
|
|
if (!output->is_available()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-10 09:14:22 +02:00
|
|
|
const ResultType result_type = get_node_socket_result_type(output);
|
Realtime Compositor: Support full precision compositing
This patch adds support for full precision compositing for the Realtime
Compositor. A new precision option was added to the compositor to change
between half and full precision compositing, where the Auto option uses
half for the viewport compositor and the interactive render compositor,
while full is used for final renders.
The compositor context now need to implement the get_precision() method
to indicate its preferred precision. Intermediate results will be stored
using the context's precision, with a number of exceptions that can use
a different precision regardless of the context's precision. For
instance, summed area tables are always stored in full float results
even if the context specified half float. Conversely, jump flooding
tables are always stored in half integer results even if the context
specified full. The former requires full float while the latter has no
use for it.
Since shaders are created for a specific precision, we need two variants
of each compositor shader to account for the context's possible
precision. However, to avoid doubling the shader info count and reduce
boilerplate code and development time, an automated mechanism was
employed. A single shader info of whatever precision needs to be added,
then, at runtime, the shader info can be adjusted to change the
precision of the outputs. That shader variant is then cached in the
static cache manager for future processing-free shader retrieval.
Therefore, the shader manager was removed in favor of a cached shader
container in the static cache manager.
A number of utilities were added to make the creation of results as well as
the retrieval of shader with the target precision easier. Further, a
number of precision-specific shaders were removed in favor of more
generic ones that utilizes the aforementioned shader retrieval
mechanism.
Pull Request: https://projects.blender.org/blender/blender/pulls/113476
2023-11-08 08:32:00 +01:00
|
|
|
populate_result(output->identifier, context.create_result(result_type));
|
2022-08-10 09:14:22 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-31 12:15:57 +02:00
|
|
|
for (const bNodeSocket *input : node->input_sockets()) {
|
2025-03-24 10:00:52 +02:00
|
|
|
if (!input->is_available()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-10 09:14:22 +02:00
|
|
|
const InputDescriptor input_descriptor = input_descriptor_from_input_socket(input);
|
2022-08-31 12:15:57 +02:00
|
|
|
declare_input_descriptor(input->identifier, input_descriptor);
|
2022-08-10 09:14:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 08:13:46 +02:00
|
|
|
void NodeOperation::evaluate()
|
|
|
|
|
{
|
|
|
|
|
const timeit::TimePoint before_time = timeit::Clock::now();
|
|
|
|
|
Operation::evaluate();
|
|
|
|
|
const timeit::TimePoint after_time = timeit::Clock::now();
|
|
|
|
|
if (context().profiler()) {
|
|
|
|
|
context().profiler()->set_node_evaluation_time(node_.instance_key(), after_time - before_time);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 05:41:49 +02:00
|
|
|
void NodeOperation::compute_preview()
|
|
|
|
|
{
|
Compositor: Avoid redundant output computations
This patch allows the compositor context to specify exactly which
outputs it needs, selecting from: Composite, Viewer, File Output, and
Previews. Previously, the compositor fully executed if any of those were
needed, without granular control on which outputs are needed exactly.
For the viewport compositor engine, it requests Composite and Viewer,
with no Previews or File Outputs.
For the render pipeline, it requests Composite and File Output, with
node Viewer or Previews.
For the interactive compositor, it requests Viewer if the backdrop is
visible or an image editor with the viewer image is visible, it requests
Compositor if an image editor with the render result is visible, it
requests Previews if a node editor has previews overlay enabled. File
outputs are never requested.
Pull Request: https://projects.blender.org/blender/blender/pulls/133960
2025-02-04 08:34:48 +01:00
|
|
|
if (bool(context().needed_outputs() & OutputTypes::Previews) && is_node_preview_needed(node())) {
|
2024-12-17 11:39:04 +01:00
|
|
|
compositor::compute_preview(context(), node(), *get_preview_result());
|
2023-06-21 05:41:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Result *NodeOperation::get_preview_result()
|
|
|
|
|
{
|
|
|
|
|
/* Find the first linked output. */
|
|
|
|
|
for (const bNodeSocket *output : node()->output_sockets()) {
|
2025-03-24 10:00:52 +02:00
|
|
|
if (!output->is_available()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 05:41:49 +02:00
|
|
|
Result &output_result = get_result(output->identifier);
|
|
|
|
|
if (output_result.should_compute()) {
|
|
|
|
|
return &output_result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* No linked outputs, find the first allocated input. */
|
|
|
|
|
for (const bNodeSocket *input : node()->input_sockets()) {
|
2025-03-24 10:00:52 +02:00
|
|
|
if (!input->is_available()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 05:41:49 +02:00
|
|
|
Result &input_result = get_input(input->identifier);
|
|
|
|
|
if (input_result.is_allocated()) {
|
|
|
|
|
return &input_result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-10 09:14:22 +02:00
|
|
|
void NodeOperation::compute_results_reference_counts(const Schedule &schedule)
|
|
|
|
|
{
|
2022-08-31 12:15:57 +02:00
|
|
|
for (const bNodeSocket *output : this->node()->output_sockets()) {
|
2025-03-24 10:00:52 +02:00
|
|
|
if (!output->is_available()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-31 12:15:57 +02:00
|
|
|
const DOutputSocket doutput{node().context(), output};
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
const int reference_count = number_of_inputs_linked_to_output_conditioned(
|
2022-08-31 12:15:57 +02:00
|
|
|
doutput, [&](DInputSocket input) { return schedule.contains(input.node()); });
|
2022-08-10 09:14:22 +02:00
|
|
|
|
2025-03-06 08:50:22 +01:00
|
|
|
get_result(doutput->identifier).set_reference_count(reference_count);
|
2022-08-10 09:14:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DNode &NodeOperation::node() const
|
|
|
|
|
{
|
|
|
|
|
return node_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bNode &NodeOperation::bnode() const
|
|
|
|
|
{
|
2022-08-31 12:15:57 +02:00
|
|
|
return *node_;
|
2022-08-10 09:14:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NodeOperation::should_compute_output(StringRef identifier)
|
|
|
|
|
{
|
|
|
|
|
return get_result(identifier).should_compute();
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-17 11:39:04 +01:00
|
|
|
} // namespace blender::compositor
|