nodes: optimize node graph changes by only updating from inputs that changed
A huge optimization that ensures only the parts of a node graph that have changed get pushed to the renderer. For thread-safety, the node graph is copied elsewhere so that users can make changes asynchronously and the graph can update when its threads are ready. Up until now, if an input value changed, every node's values would be re-copied, or worse, if a connection was changed, the entire graph would be recopied. This has been negligible in testing since we've been largely testing with small graphs, but for massive projects, it's important that this be as optimized as possible.
This commit is contained in:
@@ -174,7 +174,7 @@ void KeyframeViewBase::mouseMoveEvent(QMouseEvent *event)
|
||||
// frame gets rendered in this time
|
||||
input_parent->blockSignals(false);
|
||||
|
||||
input_parent->parentNode()->InvalidateVisible(input_parent);
|
||||
input_parent->parentNode()->InvalidateVisible(input_parent, input_parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -377,7 +377,7 @@ void KeyframeViewBase::ProcessBezierDrag(QPointF mouse_diff_scaled, bool include
|
||||
|
||||
input_parent->blockSignals(false);
|
||||
|
||||
input_parent->parentNode()->InvalidateVisible(input_parent);
|
||||
input_parent->parentNode()->InvalidateVisible(input_parent, input_parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -255,7 +255,7 @@ void NodeParamViewWidgetBridge::ProcessSlider(SliderBase *slider, const QVariant
|
||||
|
||||
input_->blockSignals(false);
|
||||
|
||||
input_->parentNode()->InvalidateVisible(input_);
|
||||
input_->parentNode()->InvalidateVisible(input_, input_);
|
||||
|
||||
} else {
|
||||
if (dragging_) {
|
||||
@@ -513,9 +513,9 @@ rational NodeParamViewWidgetBridge::GetCurrentTimeAsNodeTime() const
|
||||
return GetAdjustedTime(GetTimeTarget(), input_->parentNode(), time_, NodeParam::kInput);
|
||||
}
|
||||
|
||||
void NodeParamViewWidgetBridge::InputValueChanged(const rational &start, const rational &end)
|
||||
void NodeParamViewWidgetBridge::InputValueChanged(const TimeRange &range)
|
||||
{
|
||||
if (!dragging_ && start <= time_ && end >= time_) {
|
||||
if (!dragging_ && range.in() <= time_ && range.out() >= time_) {
|
||||
// We'll need to update the widgets because the values have changed on our current time
|
||||
UpdateWidgetValues();
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ private:
|
||||
private slots:
|
||||
void WidgetCallback();
|
||||
|
||||
void InputValueChanged(const rational& start, const rational& end);
|
||||
void InputValueChanged(const TimeRange& range);
|
||||
|
||||
void PropertyChanged(const QString& key, const QVariant& value);
|
||||
|
||||
|
||||
@@ -274,7 +274,9 @@ void TrackRippleRemoveAreaCommand::redo_internal()
|
||||
|
||||
track_->UnblockInvalidateCache();
|
||||
|
||||
track_->InvalidateCache(in_, insert_ ? out_ : RATIONAL_MAX);
|
||||
track_->InvalidateCache(TimeRange(in_, insert_ ? out_ : RATIONAL_MAX),
|
||||
track_->block_input(),
|
||||
track_->block_input());
|
||||
}
|
||||
|
||||
void TrackRippleRemoveAreaCommand::undo_internal()
|
||||
@@ -328,7 +330,7 @@ void TrackRippleRemoveAreaCommand::undo_internal()
|
||||
|
||||
track_->UnblockInvalidateCache();
|
||||
|
||||
track_->InvalidateCache(in_, insert_ ? out_ : RATIONAL_MAX);
|
||||
track_->InvalidateCache(TimeRange(in_, insert_ ? out_ : RATIONAL_MAX), track_->block_input(), track_->block_input());
|
||||
}
|
||||
|
||||
TrackPlaceBlockCommand::TrackPlaceBlockCommand(TrackList *timeline, int track, Block *block, rational in, QUndoCommand *parent) :
|
||||
|
||||
@@ -152,8 +152,8 @@ void ViewerWidget::ConnectNodeInternal(ViewerOutput *n)
|
||||
connect(n, &ViewerOutput::LengthChanged, this, &ViewerWidget::LengthChangedSlot);
|
||||
connect(n, &ViewerOutput::VideoParamsChanged, this, &ViewerWidget::UpdateRendererParameters);
|
||||
connect(n, &ViewerOutput::VisibleInvalidated, this, &ViewerWidget::InvalidateVisible);
|
||||
connect(n, &ViewerOutput::VideoGraphChanged, this, &ViewerWidget::UpdateStack);
|
||||
connect(n, &ViewerOutput::AudioGraphChanged, this, &ViewerWidget::UpdateStack);
|
||||
connect(n, &ViewerOutput::VideoChangedBetween, this, &ViewerWidget::UpdateStack);
|
||||
connect(n, &ViewerOutput::AudioChangedBetween, this, &ViewerWidget::UpdateStack);
|
||||
|
||||
SizeChangedSlot(n->video_params().width(), n->video_params().height());
|
||||
LengthChangedSlot(n->Length());
|
||||
@@ -194,8 +194,8 @@ void ViewerWidget::DisconnectNodeInternal(ViewerOutput *n)
|
||||
disconnect(n, &ViewerOutput::LengthChanged, this, &ViewerWidget::LengthChangedSlot);
|
||||
disconnect(n, &ViewerOutput::VideoParamsChanged, this, &ViewerWidget::UpdateRendererParameters);
|
||||
disconnect(n, &ViewerOutput::VisibleInvalidated, this, &ViewerWidget::InvalidateVisible);
|
||||
disconnect(n, &ViewerOutput::VideoGraphChanged, this, &ViewerWidget::UpdateStack);
|
||||
disconnect(n, &ViewerOutput::AudioGraphChanged, this, &ViewerWidget::UpdateStack);
|
||||
disconnect(n, &ViewerOutput::VideoChangedBetween, this, &ViewerWidget::UpdateStack);
|
||||
disconnect(n, &ViewerOutput::AudioChangedBetween, this, &ViewerWidget::UpdateStack);
|
||||
|
||||
// Effectively disables the viewer and clears the state
|
||||
SizeChangedSlot(0, 0);
|
||||
@@ -434,10 +434,14 @@ void ViewerWidget::SetColorTransform(const ColorTransform &transform, ViewerDisp
|
||||
|
||||
void ViewerWidget::UpdateStack()
|
||||
{
|
||||
if (!GetConnectedNode() || GetConnectedNode()->texture_input()->IsConnected()) {
|
||||
stack_->setCurrentWidget(sizer_);
|
||||
} else {
|
||||
if (GetConnectedNode()
|
||||
&& !GetConnectedNode()->texture_input()->IsConnected()
|
||||
&& GetConnectedNode()->samples_input()->IsConnected()) {
|
||||
// If we have a node AND video is disconnected AND audio is connected, show waveform view
|
||||
stack_->setCurrentWidget(waveform_view_);
|
||||
} else {
|
||||
// Otherwise show regular display
|
||||
stack_->setCurrentWidget(sizer_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,7 +531,7 @@ void ViewerWidget::UpdateRendererParameters()
|
||||
|
||||
if (video_renderer_->params() != vparam) {
|
||||
video_renderer_->SetParameters(vparam);
|
||||
video_renderer_->InvalidateCache(TimeRange(0, GetConnectedNode()->Length()));
|
||||
video_renderer_->InvalidateCache(TimeRange(0, GetConnectedNode()->Length()), nullptr);
|
||||
}
|
||||
|
||||
AudioRenderingParams aparam(GetConnectedNode()->audio_params(),
|
||||
@@ -535,7 +539,7 @@ void ViewerWidget::UpdateRendererParameters()
|
||||
|
||||
if (audio_renderer_->params() != aparam) {
|
||||
audio_renderer_->SetParameters(aparam);
|
||||
audio_renderer_->InvalidateCache(TimeRange(0, GetConnectedNode()->Length()));
|
||||
audio_renderer_->InvalidateCache(TimeRange(0, GetConnectedNode()->Length()), nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -869,9 +873,9 @@ void ViewerWidget::SetZoomFromMenu(QAction *action)
|
||||
sizer_->SetZoom(action->data().toInt());
|
||||
}
|
||||
|
||||
void ViewerWidget::InvalidateVisible()
|
||||
void ViewerWidget::InvalidateVisible(NodeInput* source)
|
||||
{
|
||||
video_renderer_->InvalidateCache(TimeRange(GetTime(), GetTime()));
|
||||
video_renderer_->InvalidateCache(TimeRange(GetTime(), GetTime()), source);
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -233,7 +233,7 @@ private slots:
|
||||
|
||||
void SetZoomFromMenu(QAction* action);
|
||||
|
||||
void InvalidateVisible();
|
||||
void InvalidateVisible(NodeInput *source);
|
||||
|
||||
void UpdateStack();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user