renderer: moved all shader code into one solidified function

Makes texture-based optimizations easier when they're all in one place.
This commit is contained in:
itsmattkc
2020-06-10 01:54:02 +10:00
parent 29537fea3c
commit 71ec148e76
35 changed files with 274 additions and 191 deletions
+5 -5
View File
@@ -32,31 +32,31 @@ Block::Block() :
next_(nullptr)
{
name_input_ = new NodeInput("name_in", NodeParam::kString);
name_input_->SetConnectable(false);
name_input_->set_connectable(false);
name_input_->set_is_keyframable(false);
AddInput(name_input_);
length_input_ = new NodeInput("length_in", NodeParam::kRational);
length_input_->SetConnectable(false);
length_input_->set_connectable(false);
length_input_->set_is_keyframable(false);
AddInput(length_input_);
disconnect(length_input_, &NodeInput::ValueChanged, this, &Block::InputChanged);
connect(length_input_, &NodeInput::ValueChanged, this, &Block::LengthInputChanged);
media_in_input_ = new NodeInput("media_in_in", NodeParam::kRational);
media_in_input_->SetConnectable(false);
media_in_input_->set_connectable(false);
media_in_input_->set_is_keyframable(false);
AddInput(media_in_input_);
enabled_input_ = new NodeInput("enabled_in", NodeParam::kBoolean);
enabled_input_->SetConnectable(false);
enabled_input_->set_connectable(false);
enabled_input_->set_is_keyframable(false);
enabled_input_->set_standard_value(true);
AddInput(enabled_input_);
speed_input_ = new NodeInput("speed_in", NodeParam::kRational);
speed_input_->set_standard_value(QVariant::fromValue(rational(1)));
speed_input_->SetConnectable(false);
speed_input_->set_connectable(false);
speed_input_->set_is_keyframable(false);
AddInput(speed_input_);
+1 -1
View File
@@ -113,7 +113,7 @@ void ClipBlock::Retranslate()
void ClipBlock::Hash(QCryptographicHash &hash, const rational &time) const
{
if (texture_input_->IsConnected()) {
if (texture_input_->is_connected()) {
rational t = InputTimeAdjustment(texture_input_, TimeRange(time, time)).in();
texture_input_->get_connected_node()->Hash(hash, t);
+2 -2
View File
@@ -139,11 +139,11 @@ void TransitionBlock::Hash(QCryptographicHash &hash, const rational &time) const
hash.addData(reinterpret_cast<const char*>(&in_prog), sizeof(double));
hash.addData(reinterpret_cast<const char*>(&out_prog), sizeof(double));
if (out_block_input_->IsConnected()) {
if (out_block_input_->is_connected()) {
out_block_input_->get_connected_node()->Hash(hash, time);
}
if (in_block_input_->IsConnected()) {
if (in_block_input_->is_connected()) {
in_block_input_->get_connected_node()->Hash(hash, time);
}
}
+2 -2
View File
@@ -44,7 +44,7 @@ MatrixGenerator::MatrixGenerator()
uniform_scale_input_ = new NodeInput("uniform_scale_in", NodeParam::kBoolean, true);
uniform_scale_input_->set_is_keyframable(false);
uniform_scale_input_->SetConnectable(false);
uniform_scale_input_->set_connectable(false);
connect(uniform_scale_input_, &NodeInput::ValueChanged, this, &MatrixGenerator::UniformScaleChanged);
AddInput(uniform_scale_input_);
@@ -96,7 +96,7 @@ NodeValueTable MatrixGenerator::Value(NodeValueDatabase &value) const
// Push matrix output
QMatrix4x4 mat = GenerateMatrix(value);
NodeValueTable output = value.Merge();
output.Push(NodeParam::kMatrix, mat);
output.Push(NodeParam::kMatrix, mat, this);
return output;
}
+1 -1
View File
@@ -366,7 +366,7 @@ QVariant NodeInput::StringToValue(const DataType& data_type, const QString &stri
void NodeInput::GetDependencies(QList<Node *> &list, bool traverse, bool exclusive_only) const
{
if (IsConnected()
if (is_connected()
&& (get_connected_output()->edges().size() == 1 || !exclusive_only)) {
Node* connected = get_connected_node();
+2 -2
View File
@@ -29,7 +29,7 @@ MediaInput::MediaInput() :
connected_footage_(nullptr)
{
footage_input_ = new NodeInput("footage_in", NodeInput::kFootage);
footage_input_->SetConnectable(false);
footage_input_->set_connectable(false);
footage_input_->set_is_keyframable(false);
connect(footage_input_, &NodeInput::ValueChanged, this, &MediaInput::FootageChanged);
AddInput(footage_input_);
@@ -63,7 +63,7 @@ NodeValueTable MediaInput::Value(NodeValueDatabase &value) const
rational media_duration = Timecode::timestamp_to_time(connected_footage_->duration(),
connected_footage_->timebase());
table.Push(NodeInput::kRational, QVariant::fromValue(media_duration), "length");
table.Push(NodeInput::kRational, QVariant::fromValue(media_duration), this, "length");
}
// Push buffer to the top of the stack
+1
View File
@@ -57,6 +57,7 @@ NodeValueTable TimeInput::Value(NodeValueDatabase &value) const
table.Push(NodeParam::kFloat,
value[QStringLiteral("global")].Get(NodeParam::kFloat, QStringLiteral("time_in")),
this,
QStringLiteral("time"));
return table;
+4 -4
View File
@@ -126,12 +126,12 @@ void NodeInputArray::InsertAt(int index)
NodeInput* this_param = sub_params_.at(i);
NodeInput* prev_param = sub_params_.at(i-1);
if (this_param->IsConnected()) {
if (this_param->is_connected()) {
// Disconnect whatever is at this parameter (presumably its connection has already been copied so we can just remove it)
NodeParam::DisconnectEdge(this_param->edges().first());
}
if (prev_param->IsConnected()) {
if (prev_param->is_connected()) {
// Get edge here (only one since it's an input)
NodeEdgePtr edge = prev_param->edges().first();
@@ -161,14 +161,14 @@ void NodeInputArray::RemoveAt(int index)
for (int i=index;i<sub_params_.size();i++) {
NodeInput* this_param = sub_params_.at(i);
if (this_param->IsConnected()) {
if (this_param->is_connected()) {
// Disconnect current edge
NodeParam::DisconnectEdge(this_param->edges().first());
}
if (i < sub_params_.size() - 1) {
NodeInput* next_param = sub_params_.at(i + 1);
if (next_param->IsConnected()) {
if (next_param->is_connected()) {
// Get edge from next param
NodeEdgePtr edge = next_param->edges().first();
+13 -11
View File
@@ -31,7 +31,7 @@ OLIVE_NAMESPACE_ENTER
MathNode::MathNode()
{
method_in_ = new NodeInput(QStringLiteral("method_in"), NodeParam::kCombo);
method_in_->SetConnectable(false);
method_in_->set_connectable(false);
method_in_->set_is_keyframable(false);
AddInput(method_in_);
@@ -244,10 +244,12 @@ NodeValueTable MathNode::Value(NodeValueDatabase &value) const
if (val_a.type() == NodeParam::kRational && val_b.type() == NodeParam::kRational && GetOperation() != kOpPower) {
// Preserve rationals
output.Push(NodeParam::kRational,
QVariant::fromValue(PerformAddSubMultDiv<rational, rational>(val_a.data().value<rational>(), val_b.data().value<rational>())));
QVariant::fromValue(PerformAddSubMultDiv<rational, rational>(val_a.data().value<rational>(), val_b.data().value<rational>())),
this);
} else {
output.Push(NodeParam::kFloat,
PerformAll<float, float>(RetrieveNumber(val_a), RetrieveNumber(val_b)));
PerformAll<float, float>(RetrieveNumber(val_a), RetrieveNumber(val_b)),
this);
}
break;
}
@@ -288,7 +290,7 @@ NodeValueTable MathNode::Value(NodeValueDatabase &value) const
{
QMatrix4x4 mat_a = val_a.data().value<QMatrix4x4>();
QMatrix4x4 mat_b = val_b.data().value<QMatrix4x4>();
output.Push(NodeParam::kMatrix, PerformAddSubMult<QMatrix4x4, QMatrix4x4>(mat_a, mat_b));
output.Push(NodeParam::kMatrix, PerformAddSubMult<QMatrix4x4, QMatrix4x4>(mat_a, mat_b), this);
break;
}
@@ -298,7 +300,7 @@ NodeValueTable MathNode::Value(NodeValueDatabase &value) const
Color col_b = val_b.data().value<Color>();
// Only add and subtract are valid operations
output.Push(NodeParam::kColor, QVariant::fromValue(PerformAddSub<Color, Color>(col_a, col_b)));
output.Push(NodeParam::kColor, QVariant::fromValue(PerformAddSub<Color, Color>(col_a, col_b)), this);
break;
}
@@ -309,7 +311,7 @@ NodeValueTable MathNode::Value(NodeValueDatabase &value) const
float num = (val_a.type() == NodeParam::kColor) ? val_b.data().toFloat() : val_a.data().toFloat();
// Only multiply and divide are valid operations
output.Push(NodeParam::kColor, QVariant::fromValue(PerformMult<Color, float>(col, num)));
output.Push(NodeParam::kColor, QVariant::fromValue(PerformMult<Color, float>(col, num)), this);
break;
}
@@ -341,7 +343,7 @@ NodeValueTable MathNode::Value(NodeValueDatabase &value) const
}
}
output.Push(NodeParam::kSamples, QVariant::fromValue(mixed_samples));
output.Push(NodeParam::kSamples, QVariant::fromValue(mixed_samples), this);
break;
}
@@ -443,17 +445,17 @@ QVector4D MathNode::RetrieveVector(const NodeValue &val)
}
}
void MathNode::PushVector(NodeValueTable *output, NodeParam::DataType type, const QVector4D &vec)
void MathNode::PushVector(NodeValueTable *output, NodeParam::DataType type, const QVector4D &vec) const
{
switch (type) {
case NodeParam::kVec2:
output->Push(type, QVector2D(vec));
output->Push(type, QVector2D(vec), this);
break;
case NodeParam::kVec3:
output->Push(type, QVector3D(vec));
output->Push(type, QVector3D(vec), this);
break;
case NodeParam::kVec4:
output->Push(type, vec);
output->Push(type, vec, this);
break;
default:
break;
+1 -1
View File
@@ -134,7 +134,7 @@ private:
static float RetrieveNumber(const NodeValue& val);
static void PushVector(NodeValueTable* output, NodeParam::DataType type, const QVector4D& vec);
void PushVector(NodeValueTable* output, NodeParam::DataType type, const QVector4D& vec) const;
NodeInput* method_in_;
+2 -2
View File
@@ -84,11 +84,11 @@ NodeInput *MergeNode::blend_in() const
void MergeNode::Hash(QCryptographicHash &hash, const rational &time) const
{
if (base_in_->IsConnected()) {
if (base_in_->is_connected()) {
base_in_->get_connected_node()->Hash(hash, time);
}
if (blend_in_->IsConnected()) {
if (blend_in_->is_connected()) {
blend_in_->get_connected_node()->Hash(hash, time);
}
}
+2 -2
View File
@@ -25,7 +25,7 @@ OLIVE_NAMESPACE_ENTER
TrigonometryNode::TrigonometryNode()
{
method_in_ = new NodeInput(QStringLiteral("method_in"), NodeParam::kCombo);
method_in_->SetConnectable(false);
method_in_->set_connectable(false);
method_in_->set_is_keyframable(false);
AddInput(method_in_);
@@ -113,7 +113,7 @@ NodeValueTable TrigonometryNode::Value(NodeValueDatabase &value) const
break;
}
table.Push(NodeParam::kFloat, x);
table.Push(NodeParam::kFloat, x, this);
return table;
}
+4 -4
View File
@@ -321,7 +321,7 @@ void Node::Hash(QCryptographicHash &hash, const rational& time) const
// For a single frame, we only care about one of the times
rational input_time = InputTimeAdjustment(input, TimeRange(time, time)).in();
if (input->IsConnected()) {
if (input->is_connected()) {
// Traverse down this edge
input->get_connected_node()->Hash(hash, input_time);
} else {
@@ -689,7 +689,7 @@ QList<TimeRange> Node::TransformTimeTo(const TimeRange &time, Node *target, Node
// If this input is connected, traverse it to see if we stumble across the specified `node`
foreach (NodeInput* input, inputs) {
if (input->IsConnected()) {
if (input->is_connected()) {
TimeRange input_adjustment = InputTimeAdjustment(input, time);
Node* connected = input->get_connected_node();
@@ -710,7 +710,7 @@ QList<TimeRange> Node::TransformTimeTo(const TimeRange &time, Node *target, Node
// If this input is connected, traverse it to see if we stumble across the specified `node`
foreach (NodeOutput* output, outputs) {
if (output->IsConnected()) {
if (output->is_connected()) {
foreach (NodeEdgePtr edge, output->edges()) {
Node* input_node = edge->input()->parentNode();
@@ -790,7 +790,7 @@ bool Node::HasParamOfType(NodeParam::Type type, bool must_be_connected) const
{
foreach (NodeParam* p, params_) {
if (p->type() == type
&& (p->IsConnected() || !must_be_connected)) {
&& (p->is_connected() || !must_be_connected)) {
return true;
}
}
+1 -1
View File
@@ -99,7 +99,7 @@ TrackOutput* TrackList::AddTrack()
}
}
if (last_track && last_track->output()->IsConnected()) {
if (last_track && last_track->output()->is_connected()) {
foreach (NodeEdgePtr edge, last_track->output()->edges()) {
if (!track_input_->ContainsSubParameter(edge->input())) {
switch (type_) {
+2 -2
View File
@@ -181,14 +181,14 @@ void ViewerOutput::VerifyLength()
rational video_length;
if (texture_input_->IsConnected()) {
if (texture_input_->is_connected()) {
NodeValueTable t = traverser.GenerateTable(texture_input_->get_connected_node(), 0, 0);
video_length = t.Get(NodeParam::kNumber, "length").value<rational>();
}
rational audio_length;
if (samples_input_->IsConnected()) {
if (samples_input_->is_connected()) {
NodeValueTable t = traverser.GenerateTable(samples_input_->get_connected_node(), 0, 0);
audio_length = t.Get(NodeParam::kNumber, "length").value<rational>();
}
+4 -4
View File
@@ -88,17 +88,17 @@ int NodeParam::index()
return parentNode()->IndexOfParameter(this);
}
bool NodeParam::IsConnected() const
bool NodeParam::is_connected() const
{
return !edges_.isEmpty();
}
bool NodeParam::IsConnectable() const
bool NodeParam::is_connectable() const
{
return connectable_;
}
void NodeParam::SetConnectable(bool connectable)
void NodeParam::set_connectable(bool connectable)
{
connectable_ = connectable;
}
@@ -117,7 +117,7 @@ void NodeParam::DisconnectAll()
NodeEdgePtr NodeParam::ConnectEdge(NodeOutput *output, NodeInput *input)
{
if (!input->IsConnectable()) {
if (!input->is_connectable()) {
return nullptr;
}
+3 -3
View File
@@ -277,10 +277,10 @@ public:
/**
* @brief Returns whether anything is connected to this parameter or not
*/
bool IsConnected() const;
bool is_connected() const;
bool IsConnectable() const;
void SetConnectable(bool connectable);
bool is_connectable() const;
void set_connectable(bool connectable);
/**
* @brief Return a list of edges (aka connections to other nodes)
+4 -15
View File
@@ -40,24 +40,13 @@ NodeValueDatabase NodeTraverser::GenerateDatabase(const Node* node, const TimeRa
NodeValueTable table = ProcessInput(input, input_time);
// Exception for Footage types where we actually retrieve some Footage data from a decoder
if (input->data_type() == NodeParam::kFootage) {
StreamPtr stream = ResolveStreamFromInput(input);
if (stream) {
FootageProcessingEvent(stream, input_time, &table);
}
}
database.Insert(input, table);
}
// Insert global variables
NodeValueTable global;
global.Push(NodeParam::kFloat, range.in().toDouble(), QStringLiteral("time_in"));
global.Push(NodeParam::kFloat, range.out().toDouble(), QStringLiteral("time_out"));
global.Push(NodeParam::kFloat, range.in().toDouble(), nullptr, QStringLiteral("time_in"));
global.Push(NodeParam::kFloat, range.out().toDouble(), nullptr, QStringLiteral("time_out"));
database.Insert(QStringLiteral("global"), global);
return database;
@@ -65,7 +54,7 @@ NodeValueDatabase NodeTraverser::GenerateDatabase(const Node* node, const TimeRa
NodeValueTable NodeTraverser::ProcessInput(NodeInput* input, const TimeRange& range)
{
if (input->IsConnected()) {
if (input->is_connected()) {
// Value will equal something from the connected node, follow it
return GenerateTable(input->get_connected_node(), range);
} else if (!input->IsArray()) {
@@ -73,7 +62,7 @@ NodeValueTable NodeTraverser::ProcessInput(NodeInput* input, const TimeRange& ra
QVariant input_value = input->get_value_at_time(range.in());
NodeValueTable table;
table.Push(input->data_type(), input_value);
table.Push(input->data_type(), input_value, input->parentNode());
return table;
}
+2 -5
View File
@@ -39,21 +39,18 @@ public:
NodeValueDatabase GenerateDatabase(const Node *node, const TimeRange &range);
static StreamPtr ResolveStreamFromInput(NodeInput* input);
protected:
NodeValueTable ProcessInput(NodeInput *input, const TimeRange &range);
virtual NodeValueTable GenerateBlockTable(const TrackOutput *track, const TimeRange& range);
virtual void FootageProcessingEvent(StreamPtr, const TimeRange&, NodeValueTable*) {}
virtual void ProcessNodeEvent(const Node*,
const TimeRange&,
NodeValueDatabase&,
NodeValueTable&) {}
private:
static StreamPtr ResolveStreamFromInput(NodeInput* input);
};
OLIVE_NAMESPACE_EXIT
+14 -7
View File
@@ -57,9 +57,16 @@ NodeValueTable NodeValueDatabase::Merge() const
return NodeValueTable::Merge(tables_.values());
}
NodeValue::NodeValue(const NodeParam::DataType &type, const QVariant &data, const QString &tag) :
NodeValue::NodeValue() :
type_(NodeParam::kNone),
from_(nullptr)
{
}
NodeValue::NodeValue(const NodeParam::DataType &type, const QVariant &data, const Node *from, const QString &tag) :
type_(type),
data_(data),
from_(from),
tag_(tag)
{
}
@@ -97,7 +104,7 @@ NodeValue NodeValueTable::GetWithMeta(const NodeParam::DataType &type, const QSt
return values_.at(value_index);
}
return NodeValue(NodeParam::kNone, QVariant());
return NodeValue();
}
QVariant NodeValueTable::Take(const NodeParam::DataType &type, const QString &tag)
@@ -113,7 +120,7 @@ NodeValue NodeValueTable::TakeWithMeta(const NodeParam::DataType &type, const QS
return values_.takeAt(value_index);
}
return NodeValue(NodeParam::kNone, QVariant());
return NodeValue();
}
void NodeValueTable::Push(const NodeValue &value)
@@ -121,9 +128,9 @@ void NodeValueTable::Push(const NodeValue &value)
values_.append(value);
}
void NodeValueTable::Push(const NodeParam::DataType &type, const QVariant &data, const QString &tag)
void NodeValueTable::Push(const NodeParam::DataType &type, const QVariant &data, const Node* from, const QString &tag)
{
Push(NodeValue(type, data, tag));
Push(NodeValue(type, data, from, tag));
}
void NodeValueTable::Prepend(const NodeValue &value)
@@ -131,9 +138,9 @@ void NodeValueTable::Prepend(const NodeValue &value)
values_.prepend(value);
}
void NodeValueTable::Prepend(const NodeParam::DataType &type, const QVariant &data, const QString &tag)
void NodeValueTable::Prepend(const NodeParam::DataType &type, const QVariant &data, const Node* from, const QString &tag)
{
Prepend(NodeValue(type, data, tag));
Prepend(NodeValue(type, data, from, tag));
}
const NodeValue &NodeValueTable::At(int index) const
+5 -4
View File
@@ -30,8 +30,8 @@ OLIVE_NAMESPACE_ENTER
class NodeValue
{
public:
NodeValue() = default;
NodeValue(const NodeParam::DataType& type, const QVariant& data, const QString& tag = QString());
NodeValue();
NodeValue(const NodeParam::DataType& type, const QVariant& data, const Node* from, const QString& tag = QString());
const NodeParam::DataType& type() const;
const QVariant& data() const;
@@ -42,6 +42,7 @@ public:
private:
NodeParam::DataType type_;
QVariant data_;
const Node* from_;
QString tag_;
};
@@ -56,9 +57,9 @@ public:
QVariant Take(const NodeParam::DataType& type, const QString& tag = QString());
NodeValue TakeWithMeta(const NodeParam::DataType& type, const QString& tag = QString());
void Push(const NodeValue& value);
void Push(const NodeParam::DataType& type, const QVariant& data, const QString& tag = QString());
void Push(const NodeParam::DataType& type, const QVariant& data, const Node *from, const QString& tag = QString());
void Prepend(const NodeValue& value);
void Prepend(const NodeParam::DataType& type, const QVariant& data, const QString& tag = QString());
void Prepend(const NodeParam::DataType& type, const QVariant& data, const Node *from, const QString& tag = QString());
const NodeValue& At(int index) const;
NodeValue TakeAt(int index);
int Count() const;