removed all dependence on NodeOutputs
If Nodes only have the one output, we don't need to do so much differentiation between them. Previous iteration used outputs as like a distinct function within a Node (e.g. length output would return one result, buffer output would produce a different result - each run different code to produce their results). Now in this iteration, it's more accurate to say a Node is just one function (which seems more appropriate for a node system anyway).
This commit is contained in:
@@ -9,15 +9,3 @@ QVariant AudioWorker::FrameToValue(FramePtr frame)
|
||||
{
|
||||
return frame->ToByteArray();
|
||||
}
|
||||
|
||||
bool AudioWorker::OutputIsAccelerated(NodeOutput *output)
|
||||
{
|
||||
Q_UNUSED(output)
|
||||
return false;
|
||||
}
|
||||
|
||||
NodeValueTable AudioWorker::RunNodeAccelerated(NodeOutput *output)
|
||||
{
|
||||
Q_UNUSED(output)
|
||||
return NodeValueTable();
|
||||
}
|
||||
|
||||
@@ -11,10 +11,6 @@ public:
|
||||
protected:
|
||||
virtual QVariant FrameToValue(FramePtr frame) override;
|
||||
|
||||
virtual bool OutputIsAccelerated(NodeOutput *output) override;
|
||||
|
||||
virtual NodeValueTable RunNodeAccelerated(NodeOutput *output) override;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
@@ -28,9 +28,9 @@ FramePtr AudioRenderWorker::RetrieveFromDecoder(DecoderPtr decoder, const TimeRa
|
||||
return decoder->RetrieveAudio(range.in(), range.out() - range.in(), audio_params_);
|
||||
}
|
||||
|
||||
NodeValueTable AudioRenderWorker::RenderBlock(NodeOutput* output, const TimeRange &range)
|
||||
NodeValueTable AudioRenderWorker::RenderBlock(TrackOutput *track, const TimeRange &range)
|
||||
{
|
||||
QList<Block*> active_blocks = ValidateBlockRange(static_cast<Block*>(output->parentNode()), range);
|
||||
QList<Block*> active_blocks = track->BlocksAtTimeRange(range);
|
||||
|
||||
// All these blocks will need to output to a buffer so we create one here
|
||||
QByteArray block_range_buffer(audio_params_.time_to_bytes(range.length()), 0);
|
||||
@@ -42,7 +42,7 @@ NodeValueTable AudioRenderWorker::RenderBlock(NodeOutput* output, const TimeRang
|
||||
TimeRange range_for_block(qMax(b->in(), range.in()),
|
||||
qMin(b->out(), range.out()));
|
||||
|
||||
NodeValueTable table = RenderAsSibling(NodeDependency(b->block_output(),
|
||||
NodeValueTable table = RenderAsSibling(NodeDependency(b,
|
||||
range_for_block));
|
||||
|
||||
QByteArray samples_from_this_block = table.Take(NodeParam::kSamples).toByteArray();
|
||||
|
||||
@@ -18,7 +18,7 @@ protected:
|
||||
|
||||
virtual FramePtr RetrieveFromDecoder(DecoderPtr decoder, const TimeRange& range) override;
|
||||
|
||||
virtual NodeValueTable RenderBlock(NodeOutput *output, const TimeRange& range) override;
|
||||
virtual NodeValueTable RenderBlock(TrackOutput *track, const TimeRange& range) override;
|
||||
|
||||
private:
|
||||
AudioRenderingParams audio_params_;
|
||||
|
||||
@@ -83,12 +83,12 @@ bool OpenGLBackend::TraverseCompiling(Node *n)
|
||||
{
|
||||
foreach (NodeParam* param, n->parameters()) {
|
||||
if (param->type() == NodeParam::kInput && param->IsConnected()) {
|
||||
NodeOutput* connected_output = static_cast<NodeInput*>(param)->get_connected_output();
|
||||
Node* connected_output = static_cast<NodeInput*>(param)->get_connected_node();
|
||||
|
||||
// Check if we have a shader or not
|
||||
if (shader_cache_.GetShader(connected_output) == nullptr) {
|
||||
// Since we don't have a shader, compile one now
|
||||
QString node_code = connected_output->parentNode()->Code(connected_output);
|
||||
QString node_code = connected_output->Code();
|
||||
|
||||
// If the node has no code, it mustn't be GPU accelerated
|
||||
if (!node_code.isEmpty()) {
|
||||
@@ -126,7 +126,7 @@ bool OpenGLBackend::TraverseCompiling(Node *n)
|
||||
}
|
||||
}
|
||||
|
||||
if (!TraverseCompiling(connected_output->parentNode())) {
|
||||
if (!TraverseCompiling(connected_output)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,33 +2,27 @@
|
||||
|
||||
#include "node/node.h"
|
||||
|
||||
OpenGLShaderCache::OpenGLShaderCache()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString OpenGLShaderCache::GenerateShaderID(NodeOutput *output)
|
||||
{
|
||||
// Creates a unique identifier for this specific node and this specific output
|
||||
return QString("%1:%2").arg(output->parentNode()->id(), output->id());
|
||||
}
|
||||
|
||||
void OpenGLShaderCache::Clear()
|
||||
{
|
||||
compiled_nodes_.clear();
|
||||
}
|
||||
|
||||
void OpenGLShaderCache::AddShader(NodeOutput *output, OpenGLShaderPtr shader)
|
||||
void OpenGLShaderCache::AddShader(Node *output, OpenGLShaderPtr shader)
|
||||
{
|
||||
compiled_nodes_.insert(GenerateShaderID(output), shader);
|
||||
}
|
||||
|
||||
OpenGLShaderPtr OpenGLShaderCache::GetShader(NodeOutput *output)
|
||||
OpenGLShaderPtr OpenGLShaderCache::GetShader(Node *output)
|
||||
{
|
||||
return compiled_nodes_.value(GenerateShaderID(output));
|
||||
}
|
||||
|
||||
bool OpenGLShaderCache::HasShader(NodeOutput *output)
|
||||
QString OpenGLShaderCache::GenerateShaderID(Node *output)
|
||||
{
|
||||
return output->id();
|
||||
}
|
||||
|
||||
bool OpenGLShaderCache::HasShader(Node *output)
|
||||
{
|
||||
return compiled_nodes_.contains(GenerateShaderID(output));
|
||||
}
|
||||
|
||||
@@ -12,18 +12,18 @@
|
||||
class OpenGLShaderCache
|
||||
{
|
||||
public:
|
||||
OpenGLShaderCache();
|
||||
OpenGLShaderCache() = default;
|
||||
|
||||
void Clear();
|
||||
|
||||
void AddShader(NodeOutput* output, OpenGLShaderPtr shader);
|
||||
void AddShader(Node* output, OpenGLShaderPtr shader);
|
||||
|
||||
OpenGLShaderPtr GetShader(NodeOutput* output);
|
||||
OpenGLShaderPtr GetShader(Node* output);
|
||||
|
||||
bool HasShader(NodeOutput* output);
|
||||
bool HasShader(Node* output);
|
||||
|
||||
private:
|
||||
QString GenerateShaderID(NodeOutput* output);
|
||||
QString GenerateShaderID(Node *output);
|
||||
|
||||
QMap<QString, OpenGLShaderPtr> compiled_nodes_;
|
||||
|
||||
|
||||
@@ -63,11 +63,6 @@ QVariant OpenGLWorker::FrameToValue(FramePtr frame)
|
||||
return QVariant::fromValue(footage_tex);
|
||||
}
|
||||
|
||||
bool OpenGLWorker::OutputIsAccelerated(NodeOutput* output)
|
||||
{
|
||||
return shader_cache_->HasShader(output);
|
||||
}
|
||||
|
||||
void OpenGLWorker::CloseInternal()
|
||||
{
|
||||
buffer_.Destroy();
|
||||
@@ -83,10 +78,13 @@ void OpenGLWorker::ParametersChangedEvent()
|
||||
}
|
||||
}
|
||||
|
||||
NodeValueTable OpenGLWorker::RunNodeAccelerated(NodeOutput *out)
|
||||
void OpenGLWorker::RunNodeAccelerated(Node *node, const NodeValueDatabase *input_params, NodeValueTable *output_params)
|
||||
{
|
||||
OpenGLShaderPtr shader = shader_cache_->GetShader(out);
|
||||
Node* node = out->parentNode();
|
||||
OpenGLShaderPtr shader = shader_cache_->GetShader(node);
|
||||
|
||||
if (shader == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create the output texture
|
||||
OpenGLTexturePtr output = std::make_shared<OpenGLTexture>();
|
||||
@@ -109,35 +107,42 @@ NodeValueTable OpenGLWorker::RunNodeAccelerated(NodeOutput *out)
|
||||
// This variable is used in the shader, let's set it to our value
|
||||
|
||||
NodeInput* input = static_cast<NodeInput*>(param);
|
||||
|
||||
// Get value from database at this input
|
||||
const NodeValueTable& input_data = (*input_params)[input];
|
||||
|
||||
// Try to get a value from it
|
||||
QVariant value = input_data.Get(input->data_type());
|
||||
|
||||
switch (input->data_type()) {
|
||||
case NodeInput::kInt:
|
||||
shader->setUniformValue(variable_location, input->value().toInt());
|
||||
shader->setUniformValue(variable_location, value.toInt());
|
||||
break;
|
||||
case NodeInput::kFloat:
|
||||
shader->setUniformValue(variable_location, input->value().toFloat());
|
||||
shader->setUniformValue(variable_location, value.toFloat());
|
||||
break;
|
||||
case NodeInput::kVec2:
|
||||
shader->setUniformValue(variable_location, input->value().value<QVector2D>());
|
||||
shader->setUniformValue(variable_location, value.value<QVector2D>());
|
||||
break;
|
||||
case NodeInput::kVec3:
|
||||
shader->setUniformValue(variable_location, input->value().value<QVector3D>());
|
||||
shader->setUniformValue(variable_location, value.value<QVector3D>());
|
||||
break;
|
||||
case NodeInput::kVec4:
|
||||
shader->setUniformValue(variable_location, input->value().value<QVector4D>());
|
||||
shader->setUniformValue(variable_location, value.value<QVector4D>());
|
||||
break;
|
||||
case NodeInput::kMatrix:
|
||||
shader->setUniformValue(variable_location, input->value().value<QMatrix4x4>());
|
||||
shader->setUniformValue(variable_location, value.value<QMatrix4x4>());
|
||||
break;
|
||||
case NodeInput::kColor:
|
||||
shader->setUniformValue(variable_location, input->value().value<QColor>());
|
||||
shader->setUniformValue(variable_location, value.value<QColor>());
|
||||
break;
|
||||
case NodeInput::kBoolean:
|
||||
shader->setUniformValue(variable_location, input->value().toBool());
|
||||
shader->setUniformValue(variable_location, value.toBool());
|
||||
break;
|
||||
case NodeInput::kTexture:
|
||||
case NodeInput::kFootage:
|
||||
{
|
||||
OpenGLTexturePtr texture = input->value().value<OpenGLTexturePtr>();
|
||||
OpenGLTexturePtr texture = value.value<OpenGLTexturePtr>();
|
||||
|
||||
functions_->glActiveTexture(GL_TEXTURE0 + input_texture_count);
|
||||
|
||||
@@ -192,7 +197,7 @@ NodeValueTable OpenGLWorker::RunNodeAccelerated(NodeOutput *out)
|
||||
|
||||
functions_->glFinish();
|
||||
|
||||
return QVariant::fromValue(output);
|
||||
output_params->Push(NodeParam::kTexture, QVariant::fromValue(output));
|
||||
}
|
||||
|
||||
void OpenGLWorker::TextureToBuffer(const QVariant &tex_in, QByteArray &buffer)
|
||||
|
||||
@@ -47,9 +47,7 @@ protected:
|
||||
|
||||
virtual QVariant FrameToValue(FramePtr frame) override;
|
||||
|
||||
virtual bool OutputIsAccelerated(NodeOutput *output) override;
|
||||
|
||||
virtual NodeValueTable RunNodeAccelerated(NodeOutput *output) override;
|
||||
virtual void RunNodeAccelerated(Node *node, const NodeValueDatabase *input_params, NodeValueTable* output_params) override;
|
||||
|
||||
virtual void TextureToBuffer(const QVariant& texture, QByteArray& buffer) override;
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ bool RenderBackend::GenerateData(const TimeRange &range)
|
||||
return false;
|
||||
}
|
||||
|
||||
NodeDependency dep = NodeDependency(GetDependentInput()->get_connected_output(), range.in(), range.out());
|
||||
NodeDependency dep = NodeDependency(GetDependentInput()->get_connected_node(), range.in(), range.out());
|
||||
|
||||
foreach (RenderWorker* worker, processors_) {
|
||||
if (worker->IsAvailable() || worker == processors_.last()) {
|
||||
|
||||
@@ -44,8 +44,7 @@ void RenderWorker::Render(NodeDependency path)
|
||||
|
||||
NodeValueTable RenderWorker::RenderAsSibling(NodeDependency dep)
|
||||
{
|
||||
NodeOutput* output = dep.node();
|
||||
Node* node = output->parentNode();
|
||||
Node* node = dep.node();
|
||||
QList<NodeInput*> connected_inputs;
|
||||
NodeValueTable value;
|
||||
|
||||
@@ -54,13 +53,11 @@ NodeValueTable RenderWorker::RenderAsSibling(NodeDependency dep)
|
||||
|
||||
// Firstly we check if this node is a "Block", if it is that means it's part of a linked list of mutually exclusive
|
||||
// nodes based on time and we might need to locate which Block to attach to
|
||||
if (node->IsBlock()
|
||||
&& (dep.range().in() < static_cast<Block*>(node)->in()
|
||||
|| dep.range().out() > static_cast<Block*>(node)->out())) {
|
||||
if (node->IsTrack()) {
|
||||
// If the range is not wholly contained in this Block, we'll need to do some extra processing
|
||||
value = RenderBlock(output, dep.range());
|
||||
value = RenderBlock(static_cast<TrackOutput*>(node), dep.range());
|
||||
} else {
|
||||
value = ProcessNodeNormally(NodeDependency(output, dep.range()));
|
||||
value = ProcessNodeNormally(NodeDependency(node, dep.range()));
|
||||
}
|
||||
|
||||
// We're done!
|
||||
@@ -76,54 +73,24 @@ DecoderCache *RenderWorker::decoder_cache()
|
||||
return decoder_cache_;
|
||||
}
|
||||
|
||||
Block *RenderWorker::ValidateBlock(Block *block, const rational& time)
|
||||
{
|
||||
Q_ASSERT(block != nullptr && time >= 0);
|
||||
|
||||
while (block->in() > time) {
|
||||
// This Block is too late, find an earlier one
|
||||
block = block->previous();
|
||||
}
|
||||
|
||||
while (block->out() <= time) {
|
||||
// This block is too early, find a later one
|
||||
if (block->next() == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
block = block->next();
|
||||
}
|
||||
|
||||
// By this point, we should have the correct Block or nullptr if there's no Block here
|
||||
return block;
|
||||
}
|
||||
|
||||
QList<Block *> RenderWorker::ValidateBlockRange(Block *n, const TimeRange &range)
|
||||
{
|
||||
QList<Block*> list;
|
||||
Block* block_at_start = ValidateBlock(n, range.in());
|
||||
Block* block_at_end = ValidateBlock(n, range.out());
|
||||
|
||||
list.append(block_at_start);
|
||||
|
||||
// If more than one block is active for this range
|
||||
if (block_at_start != block_at_end) {
|
||||
|
||||
// Collect all blocks between the start and the end
|
||||
do {
|
||||
block_at_start = block_at_start->next();
|
||||
list.append(block_at_start);
|
||||
} while (block_at_start != block_at_end);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
NodeValueTable RenderWorker::RenderInternal(const NodeDependency &path)
|
||||
{
|
||||
return RenderAsSibling(path);
|
||||
}
|
||||
|
||||
bool RenderWorker::OutputIsAccelerated(Node *output)
|
||||
{
|
||||
Q_UNUSED(output)
|
||||
return false;
|
||||
}
|
||||
|
||||
void RenderWorker::RunNodeAccelerated(Node *node, const NodeValueDatabase *input_params, NodeValueTable* output_params)
|
||||
{
|
||||
Q_UNUSED(node)
|
||||
Q_UNUSED(input_params)
|
||||
Q_UNUSED(output_params)
|
||||
}
|
||||
|
||||
StreamPtr RenderWorker::ResolveStreamFromInput(NodeInput *input)
|
||||
{
|
||||
return input->get_value_at_time(0).value<StreamPtr>();
|
||||
@@ -152,8 +119,7 @@ bool RenderWorker::IsStarted()
|
||||
|
||||
NodeValueTable RenderWorker::ProcessNodeNormally(const NodeDependency& dep)
|
||||
{
|
||||
NodeOutput* output = dep.node();
|
||||
Node* node = dep.node()->parentNode();
|
||||
Node* node = dep.node();
|
||||
|
||||
//qDebug() << "Processing" << node->id();
|
||||
|
||||
@@ -170,7 +136,7 @@ NodeValueTable RenderWorker::ProcessNodeNormally(const NodeDependency& dep)
|
||||
|
||||
if (input->IsConnected()) {
|
||||
// Value will equal something from the connected node, follow it
|
||||
table = ProcessNodeNormally(NodeDependency(input->get_connected_output(),
|
||||
table = ProcessNodeNormally(NodeDependency(input->get_connected_node(),
|
||||
input_time));
|
||||
} else {
|
||||
// Push onto the table the value at this time from the input
|
||||
@@ -184,12 +150,10 @@ NodeValueTable RenderWorker::ProcessNodeNormally(const NodeDependency& dep)
|
||||
|
||||
// By this point, the node should have all the inputs it needs to render correctly
|
||||
|
||||
NodeValueTable table = node->Value(database);
|
||||
|
||||
// Check if we have a shader for this output
|
||||
if (OutputIsAccelerated(output)) {
|
||||
// Run code
|
||||
return RunNodeAccelerated(output);
|
||||
} else {
|
||||
// Generate the value as expected
|
||||
return node->Value(database);
|
||||
}
|
||||
RunNodeAccelerated(node, &database, &table);
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QObject>
|
||||
|
||||
#include "common/constructors.h"
|
||||
#include "node/block/block.h"
|
||||
#include "node/output/track/track.h"
|
||||
#include "node/node.h"
|
||||
#include "decodercache.h"
|
||||
|
||||
@@ -35,40 +35,15 @@ signals:
|
||||
void CompletedCache(NodeDependency dep, NodeValueTable data);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Returns the block in a sequence that is active at a given time
|
||||
*
|
||||
* Blocks are connected to each other previous/next to create a BlockList or a sequence of blocks. The block that
|
||||
* is currently "active" depends on the time and only one block in a track can be active at any given time.
|
||||
*
|
||||
* Calling this function with a block and a time will traverse the provided block's track to find the block that will
|
||||
* be active at that time. The block must be valid (non-null) and the time must be valid (>= 0).
|
||||
*
|
||||
* This function may return the same block that it was called with. It will never return nullptr.
|
||||
*/
|
||||
Block *ValidateBlock(Block* block, const rational& time);
|
||||
|
||||
/**
|
||||
* @brief Returns all the blocks that could be active within a range of time
|
||||
*
|
||||
* Similar to ValidateBlock() but rather than returning one block for a single time, this function returns a list of
|
||||
* blocks that could be active within a range of time.
|
||||
*
|
||||
* The block must be valid (non-null) and the time must be valid (>= 0).
|
||||
*
|
||||
* The list will always contain at least one entry.
|
||||
*/
|
||||
QList<Block*> ValidateBlockRange(Block* n, const TimeRange& range);
|
||||
|
||||
virtual bool InitInternal() = 0;
|
||||
|
||||
virtual void CloseInternal() = 0;
|
||||
|
||||
virtual NodeValueTable RenderInternal(const NodeDependency& path);
|
||||
|
||||
virtual bool OutputIsAccelerated(NodeOutput *output) = 0;
|
||||
virtual bool OutputIsAccelerated(Node *output);
|
||||
|
||||
virtual NodeValueTable RunNodeAccelerated(NodeOutput *output) = 0;
|
||||
virtual void RunNodeAccelerated(Node *node, const NodeValueDatabase *input_params, NodeValueTable* output_params);
|
||||
|
||||
StreamPtr ResolveStreamFromInput(NodeInput* input);
|
||||
DecoderPtr ResolveDecoderFromInput(NodeInput* input);
|
||||
@@ -79,7 +54,7 @@ protected:
|
||||
|
||||
NodeValueTable ProcessNodeNormally(const NodeDependency &dep);
|
||||
|
||||
virtual NodeValueTable RenderBlock(NodeOutput *output, const TimeRange& range) = 0;
|
||||
virtual NodeValueTable RenderBlock(TrackOutput *track, const TimeRange& range) = 0;
|
||||
|
||||
DecoderCache* decoder_cache();
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ NodeValueTable VideoRenderWorker::RenderInternal(const NodeDependency& path)
|
||||
// Get hash of node graph
|
||||
// We use SHA-1 for speed (benchmarks show it's the fastest hash available to us)
|
||||
QCryptographicHash hasher(QCryptographicHash::Sha1);
|
||||
HashNodeRecursively(&hasher, path.node()->parentNode(), path.in());
|
||||
HashNodeRecursively(&hasher, path.node(), path.in());
|
||||
QByteArray hash = hasher.result();
|
||||
|
||||
NodeValueTable value;
|
||||
@@ -50,8 +50,12 @@ FramePtr VideoRenderWorker::RetrieveFromDecoder(DecoderPtr decoder, const TimeRa
|
||||
void VideoRenderWorker::HashNodeRecursively(QCryptographicHash *hash, Node* n, const rational& time)
|
||||
{
|
||||
// Resolve BlockList
|
||||
if (n->IsBlock()) {
|
||||
n = ValidateBlock(static_cast<Block*>(n), time);
|
||||
if (n->IsTrack()) {
|
||||
n = static_cast<TrackOutput*>(n)->BlockAtTime(time);
|
||||
|
||||
if (!n) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Add this Node's ID
|
||||
@@ -153,15 +157,15 @@ void VideoRenderWorker::Download(NodeDependency dep, QByteArray hash, QVariant t
|
||||
working_--;
|
||||
}
|
||||
|
||||
NodeValueTable VideoRenderWorker::RenderBlock(NodeOutput* output, const TimeRange &range)
|
||||
NodeValueTable VideoRenderWorker::RenderBlock(TrackOutput *track, const TimeRange &range)
|
||||
{
|
||||
// A frame can only have one active block so we just validate the in point of the range
|
||||
Block* active_block = ValidateBlock(static_cast<Block*>(output->parentNode()), range.in());
|
||||
Block* active_block = track->BlockAtTime(range.in());
|
||||
|
||||
NodeValueTable table;
|
||||
|
||||
if (active_block) {
|
||||
table = RenderAsSibling(NodeDependency(active_block->block_output(),
|
||||
table = RenderAsSibling(NodeDependency(active_block,
|
||||
range));
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ protected:
|
||||
|
||||
virtual FramePtr RetrieveFromDecoder(DecoderPtr decoder, const TimeRange& range) override;
|
||||
|
||||
virtual NodeValueTable RenderBlock(NodeOutput *output, const TimeRange& range) override;
|
||||
virtual NodeValueTable RenderBlock(TrackOutput *track, const TimeRange& range) override;
|
||||
|
||||
private:
|
||||
void ProcessNode();
|
||||
|
||||
Reference in New Issue
Block a user