nodes: further optimized merge node to passthrough RGB blend textures
This commit is contained in:
@@ -324,7 +324,7 @@ NodeValueTable MathNodeBase::ValueInternal(NodeValueDatabase &value, Operation o
|
||||
NodeValue(NodeValue::kMatrix, adjusted_matrix, this));
|
||||
|
||||
// It's likely an alpha channel will result from this operation
|
||||
job.SetAlphaChannelRequired(true);
|
||||
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOn);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "merge.h"
|
||||
|
||||
#include "node/traverser.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
const QString MergeNode::kBaseIn = QStringLiteral("base_in");
|
||||
@@ -93,6 +95,11 @@ NodeValueTable MergeNode::Value(const QString &output, NodeValueDatabase &value)
|
||||
table.Push(job.GetValue(kBaseIn));
|
||||
} else {
|
||||
// We have both textures, push the job
|
||||
if (base_tex->channel_count() < VideoParams::kRGBAChannelCount) {
|
||||
// Base has no alpha, therefore this merge operation will not add an alpha channel
|
||||
job.SetAlphaChannelRequired(GenerateJob::kAlphaForceOff);
|
||||
}
|
||||
|
||||
table.Push(NodeValue::kShaderJob, QVariant::fromValue(job), this);
|
||||
}
|
||||
}
|
||||
@@ -102,37 +109,34 @@ NodeValueTable MergeNode::Value(const QString &output, NodeValueDatabase &value)
|
||||
|
||||
void MergeNode::Hash(const QString &output, QCryptographicHash &hash, const rational &time, const VideoParams &video_params) const
|
||||
{
|
||||
// We do some hash optimization here. If only one of the inputs is connected, this node
|
||||
// functions as a passthrough so there's no alteration to the hash. The same is true if the
|
||||
// connected node happens to return nothing (a gap for instance). Therefore we only add our
|
||||
// fingerprint if the base AND the blend change the hash. Otherwise, we assume it's a passthrough.
|
||||
NodeTraverser traverser;
|
||||
traverser.SetCacheVideoParams(video_params);
|
||||
|
||||
Q_UNUSED(output)
|
||||
NodeValueDatabase db = traverser.GenerateDatabase(this, output, TimeRange(time, time+video_params.frame_rate_as_time_base()));
|
||||
|
||||
QByteArray current_result = hash.result();
|
||||
TexturePtr base_tex = db[kBaseIn].Get(NodeValue::kTexture).value<TexturePtr>();
|
||||
TexturePtr blend_tex = db[kBlendIn].Get(NodeValue::kTexture).value<TexturePtr>();
|
||||
|
||||
bool base_changed_hash = false;
|
||||
bool blend_changed_hash = false;
|
||||
if (base_tex || blend_tex) {
|
||||
bool passthrough_base = !blend_tex;
|
||||
bool passthrough_blend = !base_tex || (blend_tex && blend_tex->channel_count() < VideoParams::kRGBAChannelCount);
|
||||
|
||||
if (IsInputConnected(kBaseIn)) {
|
||||
NodeOutput base_output = GetConnectedOutput(kBaseIn);
|
||||
base_output.node()->Hash(base_output.output(), hash, time, video_params);
|
||||
if (!passthrough_base && !passthrough_blend) {
|
||||
// This merge will actually do something so we add a fingerprint
|
||||
hash.addData(id().toUtf8());
|
||||
}
|
||||
|
||||
QByteArray post_base_hash = hash.result();
|
||||
base_changed_hash = (post_base_hash != current_result);
|
||||
current_result = post_base_hash;
|
||||
}
|
||||
if (!passthrough_base) {
|
||||
NodeOutput blend_output = GetConnectedOutput(kBlendIn);
|
||||
blend_output.node()->Hash(blend_output.output(), hash, time, video_params);
|
||||
}
|
||||
|
||||
if(IsInputConnected(kBlendIn)) {
|
||||
NodeOutput blend_output = GetConnectedOutput(kBlendIn);
|
||||
blend_output.node()->Hash(blend_output.output(), hash, time, video_params);
|
||||
if (!passthrough_blend) {
|
||||
NodeOutput base_output = GetConnectedOutput(kBaseIn);
|
||||
base_output.node()->Hash(base_output.output(), hash, time, video_params);
|
||||
}
|
||||
|
||||
blend_changed_hash = (hash.result() != current_result);
|
||||
}
|
||||
|
||||
if (base_changed_hash && blend_changed_hash) {
|
||||
// Something changed, so we'll add our fingerprint
|
||||
hash.addData(id().toUtf8());
|
||||
Q_ASSERT(!passthrough_base || !passthrough_blend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user