began new infrastructure
Yep, this is another one of my "famous" sweeping rewrites. Expect things to break. Goals for this are: - Greatly simplify node connections (particularly with arrays) so the code requires less maintenance/is more stable - Redesign node structure to address issues where UI would stall for lengthy periods of time - Less reliance on shared ptrs/greater reliance on QObject system for inheritance/memory management - General code cleanup and improvements
This commit is contained in:
@@ -52,7 +52,6 @@ set(OLIVE_SOURCES
|
||||
render/renderprocessor.cpp
|
||||
render/renderprocessor.h
|
||||
render/shadercode.h
|
||||
render/shadervalue.h
|
||||
render/stillimagecache.h
|
||||
render/texture.cpp
|
||||
render/texture.h
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#define ACCELERATEDJOB_H
|
||||
|
||||
#include "node/input.h"
|
||||
#include "node/inputarray.h"
|
||||
#include "render/shadervalue.h"
|
||||
#include "node/value.h"
|
||||
|
||||
namespace olive {
|
||||
@@ -32,58 +30,29 @@ class AcceleratedJob {
|
||||
public:
|
||||
AcceleratedJob() = default;
|
||||
|
||||
ShaderValue GetValue(NodeInput* input) const
|
||||
NodeValue GetValue(NodeInput* input) const
|
||||
{
|
||||
return value_map_.value(input->id());
|
||||
}
|
||||
|
||||
ShaderValue GetValue(const QString& input) const
|
||||
NodeValue GetValue(const QString& input) const
|
||||
{
|
||||
return value_map_.value(input);
|
||||
}
|
||||
|
||||
void InsertValue(NodeInput* input, NodeValueDatabase& value)
|
||||
{
|
||||
ShaderValue shader_val;
|
||||
|
||||
shader_val.type = input->data_type();
|
||||
shader_val.array = input->IsArray();
|
||||
|
||||
if (input->IsArray()) {
|
||||
NodeInputArray* array = static_cast<NodeInputArray*>(input);
|
||||
QVector<QVariant> values(array->GetSize());
|
||||
|
||||
for (int j=0;j<array->GetSize();j++) {
|
||||
NodeInput* subparam = array->At(j);
|
||||
|
||||
values[j] = value[subparam].Take(subparam->data_type());
|
||||
}
|
||||
|
||||
shader_val.data = QVariant::fromValue(values);
|
||||
} else {
|
||||
NodeValue node_val = value[input].TakeWithMeta(input->data_type());
|
||||
shader_val.data = node_val.data();
|
||||
shader_val.tag = node_val.tag();
|
||||
}
|
||||
|
||||
InsertValue(input->id(), shader_val);
|
||||
InsertValue(input->id(), value[input].TakeWithMeta(input->GetDataType()));
|
||||
}
|
||||
|
||||
void InsertValue(const QString& input, const ShaderValue& value)
|
||||
void InsertValue(const QString& input, const NodeValue& value)
|
||||
{
|
||||
value_map_.insert(input, value);
|
||||
}
|
||||
|
||||
void InsertValue(NodeInput* input, const ShaderValue& value)
|
||||
{
|
||||
value_map_.insert(input->id(), value);
|
||||
}
|
||||
|
||||
void InsertValue(NodeInput* input, const NodeValue& value)
|
||||
{
|
||||
ShaderValue s(value.data(), value.type());
|
||||
s.tag = value.tag();
|
||||
value_map_.insert(input->id(), s);
|
||||
value_map_.insert(input->id(), value);
|
||||
}
|
||||
|
||||
const NodeValueMap &GetValues() const
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
|
||||
SampleJob(NodeInput* from, NodeValueDatabase& db)
|
||||
{
|
||||
samples_ = db[from].Take(NodeParam::kSamples).value<SampleBufferPtr>();
|
||||
samples_ = db[from].Take(NodeValue::kSamples).value<SampleBufferPtr>();
|
||||
}
|
||||
|
||||
SampleBufferPtr samples() const
|
||||
|
||||
@@ -367,51 +367,50 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Texture *destination, Video
|
||||
}
|
||||
|
||||
// This variable is used in the shader, let's set it
|
||||
const ShaderValue& value = it.value();
|
||||
const NodeValue& value = it.value();
|
||||
|
||||
if (value.array) {
|
||||
if (value.array()) {
|
||||
qWarning() << "FIXME: Array support is currently a stub";
|
||||
}
|
||||
|
||||
switch (value.type) {
|
||||
case NodeInput::kInt:
|
||||
switch (value.type()) {
|
||||
case NodeValue::kInt:
|
||||
// kInt technically specifies a LongLong, but OpenGL doesn't support those. This may lead to
|
||||
// over/underflows if the number is large enough, but the likelihood of that is quite low.
|
||||
shader->setUniformValue(variable_location, value.data.toInt());
|
||||
shader->setUniformValue(variable_location, value.data().toInt());
|
||||
break;
|
||||
case NodeInput::kFloat:
|
||||
case NodeValue::kFloat:
|
||||
// kFloat technically specifies a double but as above, OpenGL doesn't support those.
|
||||
shader->setUniformValue(variable_location, value.data.toFloat());
|
||||
shader->setUniformValue(variable_location, value.data().toFloat());
|
||||
break;
|
||||
case NodeInput::kVec2:
|
||||
shader->setUniformValue(variable_location, value.data.value<QVector2D>());
|
||||
case NodeValue::kVec2:
|
||||
shader->setUniformValue(variable_location, value.data().value<QVector2D>());
|
||||
break;
|
||||
case NodeInput::kVec3:
|
||||
shader->setUniformValue(variable_location, value.data.value<QVector3D>());
|
||||
case NodeValue::kVec3:
|
||||
shader->setUniformValue(variable_location, value.data().value<QVector3D>());
|
||||
break;
|
||||
case NodeInput::kVec4:
|
||||
shader->setUniformValue(variable_location, value.data.value<QVector4D>());
|
||||
case NodeValue::kVec4:
|
||||
shader->setUniformValue(variable_location, value.data().value<QVector4D>());
|
||||
break;
|
||||
case NodeInput::kMatrix:
|
||||
shader->setUniformValue(variable_location, value.data.value<QMatrix4x4>());
|
||||
case NodeValue::kMatrix:
|
||||
shader->setUniformValue(variable_location, value.data().value<QMatrix4x4>());
|
||||
break;
|
||||
case NodeInput::kCombo:
|
||||
shader->setUniformValue(variable_location, value.data.value<int>());
|
||||
case NodeValue::kCombo:
|
||||
shader->setUniformValue(variable_location, value.data().value<int>());
|
||||
break;
|
||||
case NodeInput::kColor:
|
||||
case NodeValue::kColor:
|
||||
{
|
||||
Color color = value.data.value<Color>();
|
||||
Color color = value.data().value<Color>();
|
||||
shader->setUniformValue(variable_location,
|
||||
color.red(), color.green(), color.blue(), color.alpha());
|
||||
break;
|
||||
}
|
||||
case NodeInput::kBoolean:
|
||||
shader->setUniformValue(variable_location, value.data.toBool());
|
||||
case NodeValue::kBoolean:
|
||||
shader->setUniformValue(variable_location, value.data().toBool());
|
||||
break;
|
||||
case NodeInput::kBuffer:
|
||||
case NodeInput::kTexture:
|
||||
case NodeValue::kTexture:
|
||||
{
|
||||
TexturePtr texture = value.data.value<TexturePtr>();
|
||||
TexturePtr texture = value.data().value<TexturePtr>();
|
||||
|
||||
// Set value to bound texture
|
||||
shader->setUniformValue(variable_location, textures_to_bind.size());
|
||||
@@ -433,21 +432,16 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Texture *destination, Video
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NodeInput::kSamples:
|
||||
case NodeInput::kText:
|
||||
case NodeInput::kRational:
|
||||
case NodeInput::kFont:
|
||||
case NodeInput::kFile:
|
||||
case NodeInput::kDecimal:
|
||||
case NodeInput::kNumber:
|
||||
case NodeInput::kString:
|
||||
case NodeInput::kVector:
|
||||
case NodeInput::kShaderJob:
|
||||
case NodeInput::kSampleJob:
|
||||
case NodeInput::kGenerateJob:
|
||||
case NodeInput::kFootage:
|
||||
case NodeInput::kNone:
|
||||
case NodeInput::kAny:
|
||||
case NodeValue::kSamples:
|
||||
case NodeValue::kText:
|
||||
case NodeValue::kRational:
|
||||
case NodeValue::kFont:
|
||||
case NodeValue::kFile:
|
||||
case NodeValue::kShaderJob:
|
||||
case NodeValue::kSampleJob:
|
||||
case NodeValue::kGenerateJob:
|
||||
case NodeValue::kFootage:
|
||||
case NodeValue::kNone:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -469,7 +463,7 @@ void OpenGLRenderer::Blit(QVariant s, ShaderJob job, Texture *destination, Video
|
||||
|
||||
// Ensure matrix is set, at least to identity
|
||||
shader->setUniformValue("ove_mvpmat",
|
||||
job.GetValue(QStringLiteral("ove_mvpmat")).data.value<QMatrix4x4>());
|
||||
job.GetValue(QStringLiteral("ove_mvpmat")).data().value<QMatrix4x4>());
|
||||
|
||||
// Set the viewport to the "physical" resolution of the destination
|
||||
functions_->glViewport(0, 0,
|
||||
|
||||
+123
-171
@@ -61,66 +61,13 @@ void PreviewAutoCacher::SetPaused(bool paused)
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::NodeGraphChanged(NodeInput *source)
|
||||
{
|
||||
// We need to determine:
|
||||
// - If we don't have this input, assume that it's coming soon and ignore it
|
||||
// - If we do, is this input a child of another input we're already copying?
|
||||
// - Or are any of the queued inputs children of this one?
|
||||
|
||||
// First we need to find our copy of the input being queued
|
||||
Node* our_copy_node = copy_map_.value(source->parentNode());
|
||||
|
||||
// If we don't have this node yet, assume it's coming in a later copy in which case it'll be
|
||||
// copied then
|
||||
if (!our_copy_node) {
|
||||
// Assert that there are updates coming
|
||||
Q_ASSERT(!graph_update_queue_.isEmpty());
|
||||
return;
|
||||
}
|
||||
|
||||
// If we're here, we must have this node. Determine if we're already copying a "parent" of this
|
||||
for (int i=0; i<graph_update_queue_.size(); i++) {
|
||||
NodeInput* queued_input = graph_update_queue_.at(i);
|
||||
|
||||
// If this input is already queued, nothing to be done
|
||||
if (source == queued_input) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this input supersedes an already queued input
|
||||
if ((source->IsArray() && static_cast<NodeInputArray*>(source)->sub_params().contains(queued_input))
|
||||
|| queued_input->parentNode()->OutputsTo(source, true, true)) {
|
||||
// In which case, we don't need to queue it and can queue our own
|
||||
graph_update_queue_.removeAt(i);
|
||||
disconnect(queued_input, &NodeInput::destroyed, this, &PreviewAutoCacher::QueuedInputRemoved);
|
||||
i--;
|
||||
}
|
||||
|
||||
// Check if the source is a member of this array, in which case it'll be copied eventually anyway
|
||||
if (queued_input->IsArray()
|
||||
&& static_cast<NodeInputArray*>(queued_input)->sub_params().contains(source)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if this dependency graph is already queued
|
||||
if (source->parentNode()->OutputsTo(queued_input, true, true)) {
|
||||
// In which case, no further copy is necessary
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
graph_update_queue_.append(source);
|
||||
connect(source, &NodeInput::destroyed, this, &PreviewAutoCacher::QueuedInputRemoved);
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::GenerateHashes(ViewerOutput *viewer, FrameHashCache* cache, const QVector<rational> ×, qint64 job_time)
|
||||
{
|
||||
std::vector<QByteArray> existing_hashes;
|
||||
|
||||
foreach (const rational& time, times) {
|
||||
// See if hash already exists in disk cache
|
||||
QByteArray hash = RenderManager::Hash(viewer->texture_input()->get_connected_node(), viewer->video_params(), time);
|
||||
QByteArray hash = RenderManager::Hash(viewer->texture_input()->GetConnectedNode(), viewer->video_params(), time);
|
||||
|
||||
// Check memory list since disk checking is slow
|
||||
bool hash_exists = (std::find(existing_hashes.begin(), existing_hashes.end(), hash) != existing_hashes.end());
|
||||
@@ -292,13 +239,6 @@ void PreviewAutoCacher::VideoDownloaded()
|
||||
delete watcher;
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::QueuedInputRemoved()
|
||||
{
|
||||
NodeInput* i = static_cast<NodeInput*>(sender());
|
||||
disconnect(i, &NodeInput::destroyed, this, &PreviewAutoCacher::QueuedInputRemoved);
|
||||
graph_update_queue_.removeOne(i);
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::VideoParamsChanged()
|
||||
{
|
||||
// In case the user is pressing the mouse at this exact moment
|
||||
@@ -324,27 +264,28 @@ void PreviewAutoCacher::SingleFrameFinished()
|
||||
delete watcher;
|
||||
}
|
||||
|
||||
//#define PRINT_UPDATE_QUEUE_INFO
|
||||
void PreviewAutoCacher::ProcessUpdateQueue()
|
||||
{
|
||||
#ifdef PRINT_UPDATE_QUEUE_INFO
|
||||
qint64 t = QDateTime::currentMSecsSinceEpoch();
|
||||
qDebug() << "Processing update queue of" << graph_update_queue_.size() << "elements:";
|
||||
#endif
|
||||
|
||||
while (!graph_update_queue_.isEmpty()) {
|
||||
NodeInput* i = graph_update_queue_.takeFirst();
|
||||
#ifdef PRINT_UPDATE_QUEUE_INFO
|
||||
qDebug() << " " << i->parentNode()->id() << i->id();
|
||||
#endif
|
||||
disconnect(i, &NodeInput::destroyed, this, &PreviewAutoCacher::QueuedInputRemoved);
|
||||
|
||||
CopyNodeInputValue(i);
|
||||
foreach (const QueuedJob& job, graph_update_queue_) {
|
||||
switch (job.type) {
|
||||
case QueuedJob::kNodeAdded:
|
||||
AddNode(job.node);
|
||||
break;
|
||||
case QueuedJob::kNodeRemoved:
|
||||
RemoveNode(job.node);
|
||||
break;
|
||||
case QueuedJob::kEdgeAdded:
|
||||
AddEdge(job.node, job.input, job.element);
|
||||
break;
|
||||
case QueuedJob::kEdgeRemoved:
|
||||
RemoveEdge(job.node, job.input, job.element);
|
||||
break;
|
||||
case QueuedJob::kValueChanged:
|
||||
CopyValue(job.input, job.element);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PRINT_UPDATE_QUEUE_INFO
|
||||
qDebug() << "Update queue took:" << (QDateTime::currentMSecsSinceEpoch() - t);
|
||||
#endif
|
||||
graph_update_queue_.clear();
|
||||
|
||||
last_update_time_ = QDateTime::currentMSecsSinceEpoch();
|
||||
}
|
||||
@@ -356,6 +297,63 @@ bool PreviewAutoCacher::HasActiveJobs() const
|
||||
|| !video_tasks_.isEmpty();
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::AddNode(Node *node)
|
||||
{
|
||||
// Copy node
|
||||
Node* copy = node->copy();
|
||||
|
||||
// Insert into map
|
||||
copy_map_.insert(node, copy);
|
||||
|
||||
// Copy parameters
|
||||
Node::CopyInputs(node, copy, false);
|
||||
|
||||
// Connect to each input
|
||||
foreach (NodeInput* input, node->parameters()) {
|
||||
connect(input, &NodeInput::InputConnected, this, &PreviewAutoCacher::EdgeAdded);
|
||||
connect(input, &NodeInput::InputDisconnected, this, &PreviewAutoCacher::EdgeRemoved);
|
||||
connect(input, &NodeInput::ValueChanged, this, &PreviewAutoCacher::ValueChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::RemoveNode(Node *node)
|
||||
{
|
||||
// Find our copy and remove it
|
||||
Node* copy = copy_map_.take(node);
|
||||
|
||||
// Delete it
|
||||
delete copy;
|
||||
|
||||
// Disconnect from inputs
|
||||
foreach (NodeInput* input, node->parameters()) {
|
||||
disconnect(input, &NodeInput::InputConnected, this, &PreviewAutoCacher::EdgeAdded);
|
||||
disconnect(input, &NodeInput::InputDisconnected, this, &PreviewAutoCacher::EdgeRemoved);
|
||||
disconnect(input, &NodeInput::ValueChanged, this, &PreviewAutoCacher::ValueChanged);
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::AddEdge(Node *output, NodeInput *input, int element)
|
||||
{
|
||||
Node* our_output = copy_map_.value(output);
|
||||
NodeInput* our_input = copy_map_.value(input->parent())->GetInputWithID(input->id());
|
||||
|
||||
Node::ConnectEdge(our_output, our_input, element);
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::RemoveEdge(Node *output, NodeInput *input, int element)
|
||||
{
|
||||
Node* our_output = copy_map_.value(output);
|
||||
NodeInput* our_input = copy_map_.value(input->parent())->GetInputWithID(input->id());
|
||||
|
||||
Node::DisconnectEdge(our_output, our_input, element);
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::CopyValue(NodeInput *input, int element)
|
||||
{
|
||||
NodeInput* our_input = copy_map_.value(input->parent())->GetInputWithID(input->id());
|
||||
NodeInput::CopyValuesOfElement(input, our_input, element);
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::SetPlayhead(const rational &playhead)
|
||||
{
|
||||
cache_range_ = TimeRange(playhead - Config::Current()["DiskCacheBehind"].value<rational>(),
|
||||
@@ -440,90 +438,31 @@ void PreviewAutoCacher::ClearVideoDownloadQueue(bool wait)
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::CopyNodeInputValue(NodeInput *input)
|
||||
void PreviewAutoCacher::NodeAdded(Node *node)
|
||||
{
|
||||
// Find our copy of this parameter
|
||||
Node* our_copy_node = copy_map_.value(input->parentNode());
|
||||
Q_ASSERT(our_copy_node);
|
||||
NodeInput* our_copy = our_copy_node->GetInputWithID(input->id());
|
||||
|
||||
// Copy the standard/keyframe values between these two inputs
|
||||
NodeInput::CopyValues(input,
|
||||
our_copy,
|
||||
false,
|
||||
false);
|
||||
|
||||
// Handle connections
|
||||
if (input->is_connected() || our_copy->is_connected()) {
|
||||
// If one of the inputs is connected, it's likely this change came from connecting or
|
||||
// disconnecting whatever was connected to it
|
||||
|
||||
// We start by removing all old dependencies from the map
|
||||
QVector<Node*> old_deps = our_copy->GetExclusiveDependencies();
|
||||
foreach (Node* i, old_deps) {
|
||||
copy_map_.take(copy_map_.key(i))->deleteLater();
|
||||
}
|
||||
|
||||
// And clear any other edges
|
||||
while (!our_copy->edges().isEmpty()) {
|
||||
NodeParam::DisconnectEdge(our_copy->edges().first());
|
||||
}
|
||||
|
||||
// Then we copy all node dependencies and connections (if there are any)
|
||||
CopyNodeMakeConnection(input, our_copy);
|
||||
}
|
||||
|
||||
// Call on sub-elements too
|
||||
if (input->IsArray()) {
|
||||
foreach (NodeInput* i, static_cast<NodeInputArray*>(input)->sub_params()) {
|
||||
CopyNodeInputValue(i);
|
||||
}
|
||||
}
|
||||
graph_update_queue_.append({QueuedJob::kNodeAdded, node, nullptr, -1});
|
||||
}
|
||||
|
||||
Node* PreviewAutoCacher::CopyNodeConnections(Node* src_node)
|
||||
void PreviewAutoCacher::NodeRemoved(Node *node)
|
||||
{
|
||||
// Check if this node is already in the map
|
||||
Node* dst_node = copy_map_.value(src_node);
|
||||
|
||||
// If not, create it now
|
||||
if (!dst_node) {
|
||||
dst_node = src_node->copy();
|
||||
|
||||
if (dst_node->IsTrack()) {
|
||||
// Hack that ensures the track type is set since we don't bother copying the whole timeline
|
||||
static_cast<TrackOutput*>(dst_node)->set_track_type(static_cast<TrackOutput*>(src_node)->track_type());
|
||||
}
|
||||
|
||||
copy_map_.insert(src_node, dst_node);
|
||||
}
|
||||
|
||||
// Make sure its values are copied
|
||||
Node::CopyInputs(src_node, dst_node, false);
|
||||
|
||||
// Copy all connections
|
||||
QVector<NodeInput*> src_node_inputs = src_node->GetInputsIncludingArrays();
|
||||
QVector<NodeInput*> dst_node_inputs = dst_node->GetInputsIncludingArrays();
|
||||
|
||||
for (int i=0;i<src_node_inputs.size();i++) {
|
||||
NodeInput* src_input = src_node_inputs.at(i);
|
||||
|
||||
CopyNodeMakeConnection(src_input, dst_node_inputs.at(i));
|
||||
}
|
||||
|
||||
return dst_node;
|
||||
graph_update_queue_.append({QueuedJob::kNodeRemoved, node, nullptr, -1});
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::CopyNodeMakeConnection(NodeInput* src_input, NodeInput* dst_input)
|
||||
void PreviewAutoCacher::EdgeAdded(Node *output, int element)
|
||||
{
|
||||
if (src_input->is_connected()) {
|
||||
Node* dst_node = CopyNodeConnections(src_input->get_connected_node());
|
||||
graph_update_queue_.append({QueuedJob::kEdgeAdded, output, static_cast<NodeInput*>(sender()), element});
|
||||
}
|
||||
|
||||
NodeOutput* corresponding_output = dst_node->GetOutputWithID(src_input->get_connected_output()->id());
|
||||
void PreviewAutoCacher::EdgeRemoved(Node *output, int element)
|
||||
{
|
||||
graph_update_queue_.append({QueuedJob::kEdgeRemoved, output, static_cast<NodeInput*>(sender()), element});
|
||||
}
|
||||
|
||||
NodeParam::ConnectEdge(corresponding_output,
|
||||
dst_input);
|
||||
}
|
||||
void PreviewAutoCacher::ValueChanged(const TimeRange &range, int element)
|
||||
{
|
||||
Q_UNUSED(range)
|
||||
|
||||
graph_update_queue_.append({QueuedJob::kValueChanged, nullptr, static_cast<NodeInput*>(sender()), element});
|
||||
}
|
||||
|
||||
void PreviewAutoCacher::TryRender()
|
||||
@@ -701,12 +640,13 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node)
|
||||
video_params_changed_ = false;
|
||||
audio_params_changed_ = false;
|
||||
|
||||
// Disconnect signal (will be a no-op if the signal was never connected)
|
||||
disconnect(viewer_node_,
|
||||
&ViewerOutput::GraphChangedFrom,
|
||||
this,
|
||||
&PreviewAutoCacher::NodeGraphChanged);
|
||||
// Disconnect signals for future node additions/deletions
|
||||
NodeGraph* graph = viewer_node_->parent();
|
||||
|
||||
connect(graph, &NodeGraph::NodeAdded, this, &PreviewAutoCacher::NodeAdded);
|
||||
connect(graph, &NodeGraph::NodeRemoved, this, &PreviewAutoCacher::NodeRemoved);
|
||||
|
||||
// Disconnect signal (will be a no-op if the signal was never connected)
|
||||
disconnect(viewer_node_,
|
||||
&ViewerOutput::VideoParamsChanged,
|
||||
this,
|
||||
@@ -732,28 +672,40 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node)
|
||||
|
||||
if (viewer_node_) {
|
||||
// Copy graph
|
||||
copied_viewer_node_ = static_cast<ViewerOutput*>(viewer_node_->copy());
|
||||
copy_map_.insert(viewer_node_, copied_viewer_node_);
|
||||
NodeGraph* graph = viewer_node_->parent();
|
||||
|
||||
// Add all nodes
|
||||
foreach (Node* node, graph->nodes()) {
|
||||
AddNode(node);
|
||||
}
|
||||
|
||||
// Find copied viewer node
|
||||
copied_viewer_node_ = static_cast<ViewerOutput*>(copy_map_.value(viewer_node_));
|
||||
|
||||
// Copy parameters
|
||||
copied_viewer_node_->set_video_params(viewer_node_->video_params());
|
||||
copied_viewer_node_->set_audio_params(viewer_node_->audio_params());
|
||||
|
||||
// We begin an operation and never end it which prevents the copy from unnecessarily
|
||||
// invalidating its own cache
|
||||
copied_viewer_node_->BeginOperation();
|
||||
// Add all connections
|
||||
foreach (Node* node, graph->nodes()) {
|
||||
foreach (NodeInput* input, node->inputs()) {
|
||||
for (auto it=input->edges().cbegin(); it!=input->edges().cend(); it++) {
|
||||
AddEdge(it.value(), input, it.key());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NodeGraphChanged(viewer_node_->texture_input());
|
||||
NodeGraphChanged(viewer_node_->samples_input());
|
||||
ProcessUpdateQueue();
|
||||
// Connect signals for future node additions/deletions
|
||||
connect(graph, &NodeGraph::NodeAdded, this, &PreviewAutoCacher::NodeAdded);
|
||||
connect(graph, &NodeGraph::NodeRemoved, this, &PreviewAutoCacher::NodeRemoved);
|
||||
|
||||
// Copy invalidated ranges - used to determine which frames need hashing
|
||||
invalidated_video_ = viewer_node_->video_frame_cache()->GetInvalidatedRanges();
|
||||
invalidated_audio_ = viewer_node_->audio_playback_cache()->GetInvalidatedRanges();
|
||||
|
||||
connect(viewer_node_,
|
||||
&ViewerOutput::GraphChangedFrom,
|
||||
this,
|
||||
&PreviewAutoCacher::NodeGraphChanged);
|
||||
// We begin an operation and never end it which prevents the copy from unnecessarily
|
||||
// invalidating its own cache
|
||||
copied_viewer_node_->BeginOperation();
|
||||
|
||||
connect(viewer_node_,
|
||||
&ViewerOutput::VideoParamsChanged,
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
#include "config/config.h"
|
||||
#include "node/graph.h"
|
||||
#include "node/node.h"
|
||||
#include "node/output/viewer/viewer.h"
|
||||
#include "render/colormanager.h"
|
||||
@@ -93,15 +94,19 @@ public slots:
|
||||
/**
|
||||
* @brief Main handler for when the NodeGraph changes
|
||||
*/
|
||||
void NodeGraphChanged(NodeInput *source);
|
||||
void NodeAdded(Node* node);
|
||||
|
||||
void NodeRemoved(Node* node);
|
||||
|
||||
void EdgeAdded(Node* output, int element);
|
||||
|
||||
void EdgeRemoved(Node* output, int element);
|
||||
|
||||
void ValueChanged(const TimeRange& range, int element);
|
||||
|
||||
private:
|
||||
static void GenerateHashes(ViewerOutput* viewer, FrameHashCache *cache, const QVector<rational>& times, qint64 job_time);
|
||||
|
||||
void CopyNodeInputValue(NodeInput* input);
|
||||
Node *CopyNodeConnections(Node *src_node);
|
||||
void CopyNodeMakeConnection(NodeInput *src_input, NodeInput *dst_input);
|
||||
|
||||
void TryRender();
|
||||
|
||||
/**
|
||||
@@ -114,12 +119,34 @@ private:
|
||||
|
||||
bool HasActiveJobs() const;
|
||||
|
||||
QList<NodeInput*> graph_update_queue_;
|
||||
QHash<Node*, Node*> copy_map_;
|
||||
ViewerOutput* copied_viewer_node_;
|
||||
void AddNode(Node* node);
|
||||
void RemoveNode(Node* node);
|
||||
void AddEdge(Node* output, NodeInput* input, int element);
|
||||
void RemoveEdge(Node* output, NodeInput* input, int element);
|
||||
void CopyValue(NodeInput* input, int element);
|
||||
|
||||
class QueuedJob {
|
||||
public:
|
||||
enum Type {
|
||||
kNodeAdded,
|
||||
kNodeRemoved,
|
||||
kEdgeAdded,
|
||||
kEdgeRemoved,
|
||||
kValueChanged
|
||||
};
|
||||
|
||||
Type type;
|
||||
Node* node;
|
||||
NodeInput* input;
|
||||
int element;
|
||||
};
|
||||
|
||||
ViewerOutput* viewer_node_;
|
||||
|
||||
QVector<QueuedJob> graph_update_queue_;
|
||||
QHash<Node*, Node*> copy_map_;
|
||||
ViewerOutput* copied_viewer_node_;
|
||||
|
||||
bool paused_;
|
||||
|
||||
TimeRange cache_range_;
|
||||
@@ -184,15 +211,6 @@ private slots:
|
||||
*/
|
||||
void VideoDownloaded();
|
||||
|
||||
/**
|
||||
* @brief Handler for when a NodeInput has been deleted so we clear it from the queue
|
||||
*
|
||||
* FIXME: This is hacky. It also might not be necessary anymore with recent changes to the
|
||||
* node system, but I haven't tested yet. Either way, PreviewAutoCacher should probably
|
||||
* be able to pick up on these sorts of things without such a slot.
|
||||
*/
|
||||
void QueuedInputRemoved();
|
||||
|
||||
void VideoParamsChanged();
|
||||
|
||||
void AudioParamsChanged();
|
||||
|
||||
@@ -236,8 +236,8 @@ void Renderer::BlitColorManagedInternal(ColorProcessorPtr color_processor, Textu
|
||||
|
||||
ShaderJob job;
|
||||
|
||||
job.InsertValue(QStringLiteral("ove_maintex"), ShaderValue(QVariant::fromValue(source), NodeParam::kTexture));
|
||||
job.InsertValue(QStringLiteral("ove_mvpmat"), ShaderValue(matrix, NodeParam::kMatrix));
|
||||
job.InsertValue(QStringLiteral("ove_maintex"), NodeValue(NodeValue::kTexture, QVariant::fromValue(source)));
|
||||
job.InsertValue(QStringLiteral("ove_mvpmat"), NodeValue(NodeValue::kMatrix, matrix));
|
||||
|
||||
AlphaAssociated associated;
|
||||
if (source->channel_count() == VideoParams::kRGBAChannelCount) {
|
||||
@@ -252,14 +252,14 @@ void Renderer::BlitColorManagedInternal(ColorProcessorPtr color_processor, Textu
|
||||
// No assoc/deassoc required
|
||||
associated = kAlphaNone;
|
||||
}
|
||||
job.InsertValue(QStringLiteral("ove_maintex_alpha"), ShaderValue(associated, NodeParam::kInt));
|
||||
job.InsertValue(QStringLiteral("ove_maintex_alpha"), NodeValue(NodeValue::kInt, associated));
|
||||
|
||||
foreach (const ColorContext::LUT& l, color_ctx.lut3d_textures) {
|
||||
job.InsertValue(l.name, ShaderValue(QVariant::fromValue(l.texture), NodeParam::kTexture));
|
||||
job.InsertValue(l.name, NodeValue(NodeValue::kTexture, QVariant::fromValue(l.texture)));
|
||||
job.SetInterpolation(l.name, l.interpolation);
|
||||
}
|
||||
foreach (const ColorContext::LUT& l, color_ctx.lut1d_textures) {
|
||||
job.InsertValue(l.name, ShaderValue(QVariant::fromValue(l.texture), NodeParam::kTexture));
|
||||
job.InsertValue(l.name, NodeValue(NodeValue::kTexture, QVariant::fromValue(l.texture)));
|
||||
job.SetInterpolation(l.name, l.interpolation);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ void RenderProcessor::Run()
|
||||
NodeValueTable table = ProcessInput(viewer->texture_input(),
|
||||
TimeRange(time, time + video_params.time_base()));
|
||||
|
||||
TexturePtr texture = table.Get(NodeParam::kTexture).value<TexturePtr>();
|
||||
TexturePtr texture = table.Get(NodeValue::kTexture).value<TexturePtr>();
|
||||
|
||||
// Set up output frame parameters
|
||||
VideoParams frame_params = ticket_->property("vparam").value<VideoParams>();
|
||||
@@ -112,8 +112,8 @@ void RenderProcessor::Run()
|
||||
} else {
|
||||
// No color transform, just blit
|
||||
ShaderJob job;
|
||||
job.InsertValue(QStringLiteral("ove_maintex"), {QVariant::fromValue(texture), NodeParam::kTexture});
|
||||
job.InsertValue(QStringLiteral("ove_mvpmat"), {matrix, NodeParam::kMatrix});
|
||||
job.InsertValue(QStringLiteral("ove_maintex"), NodeValue(NodeValue::kTexture, QVariant::fromValue(texture)));
|
||||
job.InsertValue(QStringLiteral("ove_mvpmat"), NodeValue(NodeValue::kMatrix, matrix));
|
||||
|
||||
render_ctx_->BlitToTexture(default_shader_, job, blit_tex.get());
|
||||
}
|
||||
@@ -135,7 +135,7 @@ void RenderProcessor::Run()
|
||||
|
||||
NodeValueTable table = ProcessInput(viewer->samples_input(), time);
|
||||
|
||||
ticket_->Finish(table.Get(NodeParam::kSamples), IsCancelled());
|
||||
ticket_->Finish(table.Get(NodeValue::kSamples), IsCancelled());
|
||||
break;
|
||||
}
|
||||
case RenderManager::kTypeVideoDownload:
|
||||
@@ -211,7 +211,7 @@ NodeValueTable RenderProcessor::GenerateBlockTable(const TrackOutput *track, con
|
||||
|
||||
// Destination buffer
|
||||
NodeValueTable table = GenerateTable(b, range_for_block);
|
||||
SampleBufferPtr samples_from_this_block = table.Take(NodeParam::kSamples).value<SampleBufferPtr>();
|
||||
SampleBufferPtr samples_from_this_block = table.Take(NodeValue::kSamples).value<SampleBufferPtr>();
|
||||
|
||||
if (!samples_from_this_block) {
|
||||
// If we retrieved no samples from this block, do nothing
|
||||
@@ -219,10 +219,10 @@ NodeValueTable RenderProcessor::GenerateBlockTable(const TrackOutput *track, con
|
||||
}
|
||||
|
||||
// FIXME: Doesn't handle reversing
|
||||
if (b->speed_input()->is_keyframing() || b->speed_input()->is_connected()) {
|
||||
if (b->speed_input()->IsKeyframing() || b->speed_input()->IsConnected()) {
|
||||
// FIXME: We'll need to calculate the speed hoo boy
|
||||
} else {
|
||||
double speed_value = b->speed_input()->get_standard_value().toDouble();
|
||||
double speed_value = b->speed_input()->GetStandardValue().toDouble();
|
||||
|
||||
if (qIsNull(speed_value)) {
|
||||
// Just silence, don't think there's any other practical application of 0 speed audio
|
||||
@@ -253,7 +253,7 @@ NodeValueTable RenderProcessor::GenerateBlockTable(const TrackOutput *track, con
|
||||
ticket_->setProperty("waveforms", QVariant::fromValue(waveform_list));
|
||||
}
|
||||
|
||||
merged_table.Push(NodeParam::kSamples, QVariant::fromValue(block_range_buffer), track);
|
||||
merged_table.Push(NodeValue::kSamples, QVariant::fromValue(block_range_buffer), track);
|
||||
|
||||
return merged_table;
|
||||
|
||||
@@ -409,8 +409,8 @@ QVariant RenderProcessor::ProcessShader(const Node *node, const TimeRange &range
|
||||
|
||||
bool input_textures_have_alpha = false;
|
||||
for (auto it=job.GetValues().cbegin(); it!=job.GetValues().cend(); it++) {
|
||||
if (it.value().type == NodeParam::kTexture) {
|
||||
TexturePtr tex = it.value().data.value<TexturePtr>();
|
||||
if (it.value().type() == NodeValue::kTexture) {
|
||||
TexturePtr tex = it.value().data().value<TexturePtr>();
|
||||
if (tex && tex->channel_count() == VideoParams::kRGBAChannelCount) {
|
||||
input_textures_have_alpha = true;
|
||||
break;
|
||||
@@ -458,7 +458,7 @@ QVariant RenderProcessor::ProcessSamples(const Node *node, const TimeRange &rang
|
||||
if (corresponding_input) {
|
||||
value = ProcessInput(corresponding_input, TimeRange(this_sample_time, this_sample_time));
|
||||
} else {
|
||||
value.Push(j.value(), node);
|
||||
value.Push(j.value());
|
||||
}
|
||||
|
||||
value_db.Insert(j.key(), value);
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2020 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef SHADERVALUE_H
|
||||
#define SHADERVALUE_H
|
||||
|
||||
#include "node/param.h"
|
||||
|
||||
namespace olive {
|
||||
|
||||
struct ShaderValue
|
||||
{
|
||||
ShaderValue()
|
||||
{
|
||||
type = NodeParam::kNone;
|
||||
array = false;
|
||||
}
|
||||
|
||||
ShaderValue(QVariant data_in, NodeParam::DataType type_in, bool array_in = false)
|
||||
{
|
||||
data = data_in;
|
||||
type = type_in;
|
||||
array = array_in;
|
||||
}
|
||||
|
||||
NodeParam::DataType type;
|
||||
QVariant data;
|
||||
bool array;
|
||||
|
||||
QString tag;
|
||||
|
||||
};
|
||||
|
||||
using NodeValueMap = QHash<QString, ShaderValue>;
|
||||
|
||||
}
|
||||
|
||||
#endif // SHADERVALUE_H
|
||||
Reference in New Issue
Block a user