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
|
|
|
|
|
|
|
|
#include <limits>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
#include "BLI_map.hh"
|
|
|
|
|
#include "BLI_string_ref.hh"
|
|
|
|
|
|
|
|
|
|
#include "COM_context.hh"
|
|
|
|
|
#include "COM_conversion_operation.hh"
|
|
|
|
|
#include "COM_domain.hh"
|
|
|
|
|
#include "COM_input_descriptor.hh"
|
|
|
|
|
#include "COM_operation.hh"
|
|
|
|
|
#include "COM_realize_on_domain_operation.hh"
|
|
|
|
|
#include "COM_result.hh"
|
|
|
|
|
#include "COM_simple_operation.hh"
|
|
|
|
|
|
2024-12-17 11:39:04 +01:00
|
|
|
namespace blender::compositor {
|
2022-08-10 09:14:22 +02:00
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
Operation::Operation(Context &context) : context_(context) {}
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
Operation::~Operation() = default;
|
|
|
|
|
|
|
|
|
|
void Operation::evaluate()
|
|
|
|
|
{
|
|
|
|
|
evaluate_input_processors();
|
|
|
|
|
|
|
|
|
|
execute();
|
|
|
|
|
|
2023-06-21 05:41:49 +02:00
|
|
|
compute_preview();
|
|
|
|
|
|
2022-08-10 09:14:22 +02:00
|
|
|
release_inputs();
|
2023-04-09 09:06:41 +02:00
|
|
|
|
2024-04-16 09:10:36 +02:00
|
|
|
context().evaluate_operation_post();
|
2022-08-10 09:14:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Result &Operation::get_result(StringRef identifier)
|
|
|
|
|
{
|
|
|
|
|
return results_.lookup(identifier);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Operation::map_input_to_result(StringRef identifier, Result *result)
|
|
|
|
|
{
|
|
|
|
|
results_mapped_to_inputs_.add_new(identifier, result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 13:46:26 +03:00
|
|
|
void Operation::free_results()
|
|
|
|
|
{
|
|
|
|
|
for (Result &result : results_.values()) {
|
|
|
|
|
result.free();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-10 09:14:22 +02:00
|
|
|
Domain Operation::compute_domain()
|
|
|
|
|
{
|
|
|
|
|
/* Default to an identity domain in case no domain input was found, most likely because all
|
|
|
|
|
* inputs are single values. */
|
|
|
|
|
Domain operation_domain = Domain::identity();
|
|
|
|
|
int current_domain_priority = std::numeric_limits<int>::max();
|
|
|
|
|
|
|
|
|
|
/* Go over the inputs and find the domain of the non single value input with the highest domain
|
|
|
|
|
* priority. */
|
|
|
|
|
for (StringRef identifier : input_descriptors_.keys()) {
|
|
|
|
|
const Result &result = get_input(identifier);
|
|
|
|
|
const InputDescriptor &descriptor = get_input_descriptor(identifier);
|
|
|
|
|
|
|
|
|
|
/* A single value input can't be a domain input. */
|
|
|
|
|
if (result.is_single_value() || descriptor.expects_single_value) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-18 10:00:16 +02:00
|
|
|
/* An input that skips operation domain realization can't be a domain input. */
|
2025-01-31 10:14:54 +01:00
|
|
|
if (descriptor.realization_mode != InputRealizationMode::OperationDomain) {
|
2022-09-09 14:22:03 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-10 09:14:22 +02:00
|
|
|
/* Notice that the lower the domain priority value is, the higher the priority is, hence the
|
|
|
|
|
* less than comparison. */
|
|
|
|
|
if (descriptor.domain_priority < current_domain_priority) {
|
|
|
|
|
operation_domain = result.domain();
|
|
|
|
|
current_domain_priority = descriptor.domain_priority;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return operation_domain;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Operation::add_and_evaluate_input_processors()
|
|
|
|
|
{
|
|
|
|
|
/* Each input processor type is added to all inputs entirely before the next type. This is done
|
|
|
|
|
* because the construction of the input processors may depend on the result of previous input
|
|
|
|
|
* processors for all inputs. For instance, the realize on domain input processor considers the
|
|
|
|
|
* value of all inputs, so previous input processors for all inputs needs to be added and
|
2022-09-06 16:25:20 +10:00
|
|
|
* evaluated first. */
|
2022-08-10 09:14:22 +02:00
|
|
|
|
|
|
|
|
for (const StringRef &identifier : results_mapped_to_inputs_.keys()) {
|
|
|
|
|
SimpleOperation *conversion = ConversionOperation::construct_if_needed(
|
|
|
|
|
context(), get_input(identifier), get_input_descriptor(identifier));
|
|
|
|
|
add_and_evaluate_input_processor(identifier, conversion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const StringRef &identifier : results_mapped_to_inputs_.keys()) {
|
|
|
|
|
SimpleOperation *realize_on_domain = RealizeOnDomainOperation::construct_if_needed(
|
|
|
|
|
context(), get_input(identifier), get_input_descriptor(identifier), compute_domain());
|
|
|
|
|
add_and_evaluate_input_processor(identifier, realize_on_domain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Operation::add_and_evaluate_input_processor(StringRef identifier, SimpleOperation *processor)
|
|
|
|
|
{
|
|
|
|
|
/* Allow null inputs to facilitate construct_if_needed pattern of addition. For instance, see the
|
|
|
|
|
* implementation of the add_and_evaluate_input_processors method. */
|
|
|
|
|
if (!processor) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProcessorsVector &processors = input_processors_.lookup_or_add_default(identifier);
|
|
|
|
|
|
|
|
|
|
/* Get the result that should serve as the input for the processor. This is either the result
|
|
|
|
|
* mapped to the input or the result of the last processor depending on whether this is the first
|
|
|
|
|
* processor or not. */
|
|
|
|
|
Result &result = processors.is_empty() ? get_input(identifier) : processors.last()->get_result();
|
|
|
|
|
|
|
|
|
|
/* Map the input result of the processor and add it to the processors vector. */
|
|
|
|
|
processor->map_input_to_result(&result);
|
|
|
|
|
processors.append(std::unique_ptr<SimpleOperation>(processor));
|
|
|
|
|
|
|
|
|
|
/* Switch the result mapped to the input to be the output result of the processor. */
|
|
|
|
|
switch_result_mapped_to_input(identifier, &processor->get_result());
|
|
|
|
|
|
|
|
|
|
processor->evaluate();
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 05:41:49 +02:00
|
|
|
void Operation::compute_preview(){};
|
|
|
|
|
|
2022-08-10 09:14:22 +02:00
|
|
|
Result &Operation::get_input(StringRef identifier) const
|
|
|
|
|
{
|
|
|
|
|
return *results_mapped_to_inputs_.lookup(identifier);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Operation::switch_result_mapped_to_input(StringRef identifier, Result *result)
|
|
|
|
|
{
|
|
|
|
|
results_mapped_to_inputs_.lookup(identifier) = result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Operation::populate_result(StringRef identifier, Result result)
|
|
|
|
|
{
|
|
|
|
|
results_.add_new(identifier, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Operation::declare_input_descriptor(StringRef identifier, InputDescriptor descriptor)
|
|
|
|
|
{
|
|
|
|
|
input_descriptors_.add_new(identifier, descriptor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InputDescriptor &Operation::get_input_descriptor(StringRef identifier)
|
|
|
|
|
{
|
|
|
|
|
return input_descriptors_.lookup(identifier);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
Context &Operation::context() const
|
2022-08-10 09:14:22 +02:00
|
|
|
{
|
|
|
|
|
return context_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Operation::evaluate_input_processors()
|
|
|
|
|
{
|
|
|
|
|
if (!input_processors_added_) {
|
|
|
|
|
add_and_evaluate_input_processors();
|
|
|
|
|
input_processors_added_ = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const ProcessorsVector &processors : input_processors_.values()) {
|
|
|
|
|
for (const std::unique_ptr<SimpleOperation> &processor : processors) {
|
|
|
|
|
processor->evaluate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Operation::release_inputs()
|
|
|
|
|
{
|
|
|
|
|
for (Result *result : results_mapped_to_inputs_.values()) {
|
|
|
|
|
result->release();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-17 11:39:04 +01:00
|
|
|
} // namespace blender::compositor
|