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:
@@ -67,7 +67,7 @@ bool OpenGLProxy::Init()
|
||||
return true;
|
||||
}
|
||||
|
||||
NodeValue OpenGLProxy::FrameToValue(FramePtr frame, StreamPtr stream, const VideoParams& params, const RenderMode::Mode& mode)
|
||||
QVariant OpenGLProxy::FrameToValue(FramePtr frame, StreamPtr stream, const VideoParams& params, const RenderMode::Mode& mode)
|
||||
{
|
||||
ImageStreamPtr video_stream = std::static_pointer_cast<ImageStream>(stream);
|
||||
|
||||
@@ -167,12 +167,12 @@ NodeValue OpenGLProxy::FrameToValue(FramePtr frame, StreamPtr stream, const Vide
|
||||
footage_tex_ref = associated_tex_ref;
|
||||
}
|
||||
|
||||
return NodeValue(NodeParam::kTexture, QVariant::fromValue(footage_tex_ref));
|
||||
return QVariant::fromValue(footage_tex_ref);
|
||||
}
|
||||
|
||||
NodeValue OpenGLProxy::PreCachedFrameToValue(FramePtr frame)
|
||||
QVariant OpenGLProxy::PreCachedFrameToValue(FramePtr frame)
|
||||
{
|
||||
return NodeValue(NodeParam::kTexture, QVariant::fromValue(texture_cache_.Get(ctx_, frame)));
|
||||
return QVariant::fromValue(texture_cache_.Get(ctx_, frame));
|
||||
}
|
||||
|
||||
void OpenGLProxy::Close()
|
||||
@@ -185,10 +185,9 @@ void OpenGLProxy::Close()
|
||||
ctx_ = nullptr;
|
||||
}
|
||||
|
||||
void OpenGLProxy::RunNodeAccelerated(const Node *node,
|
||||
QVariant OpenGLProxy::RunNodeAccelerated(const Node *node,
|
||||
const TimeRange &range,
|
||||
NodeValueDatabase &input_params,
|
||||
NodeValueTable &output_params,
|
||||
const VideoParams& params)
|
||||
{
|
||||
OpenGLShaderPtr shader = shader_cache_.value(node->ShaderID(input_params));
|
||||
@@ -426,7 +425,7 @@ void OpenGLProxy::RunNodeAccelerated(const Node *node,
|
||||
|
||||
shader->release();
|
||||
|
||||
output_params.Push(NodeParam::kTexture, QVariant::fromValue(output_tex));
|
||||
return QVariant::fromValue(output_tex);
|
||||
}
|
||||
|
||||
void OpenGLProxy::TextureToBuffer(const QVariant& tex_in,
|
||||
|
||||
@@ -67,22 +67,21 @@ public:
|
||||
void Close();
|
||||
|
||||
public slots:
|
||||
void RunNodeAccelerated(const OLIVE_NAMESPACE::Node *node,
|
||||
const OLIVE_NAMESPACE::TimeRange &range,
|
||||
OLIVE_NAMESPACE::NodeValueDatabase &input_params,
|
||||
OLIVE_NAMESPACE::NodeValueTable& output_params,
|
||||
const OLIVE_NAMESPACE::VideoParams ¶ms);
|
||||
QVariant RunNodeAccelerated(const OLIVE_NAMESPACE::Node *node,
|
||||
const OLIVE_NAMESPACE::TimeRange &range,
|
||||
OLIVE_NAMESPACE::NodeValueDatabase &input_params,
|
||||
const OLIVE_NAMESPACE::VideoParams ¶ms);
|
||||
|
||||
void TextureToBuffer(const QVariant& texture,
|
||||
OLIVE_NAMESPACE::FramePtr frame,
|
||||
const QMatrix4x4& matrix);
|
||||
|
||||
OLIVE_NAMESPACE::NodeValue FrameToValue(OLIVE_NAMESPACE::FramePtr frame,
|
||||
OLIVE_NAMESPACE::StreamPtr stream,
|
||||
const OLIVE_NAMESPACE::VideoParams ¶ms,
|
||||
const OLIVE_NAMESPACE::RenderMode::Mode &mode);
|
||||
QVariant FrameToValue(OLIVE_NAMESPACE::FramePtr frame,
|
||||
OLIVE_NAMESPACE::StreamPtr stream,
|
||||
const OLIVE_NAMESPACE::VideoParams ¶ms,
|
||||
const OLIVE_NAMESPACE::RenderMode::Mode &mode);
|
||||
|
||||
OLIVE_NAMESPACE::NodeValue PreCachedFrameToValue(OLIVE_NAMESPACE::FramePtr frame);
|
||||
QVariant PreCachedFrameToValue(OLIVE_NAMESPACE::FramePtr frame);
|
||||
|
||||
private:
|
||||
QOpenGLContext* ctx_;
|
||||
|
||||
@@ -38,41 +38,49 @@ void OpenGLWorker::TextureToFrame(const QVariant &texture, FramePtr frame, const
|
||||
Q_ARG(const QMatrix4x4&, mat));
|
||||
}
|
||||
|
||||
NodeValue OpenGLWorker::FrameToTexture(DecoderPtr decoder, StreamPtr stream, const TimeRange &range) const
|
||||
QVariant OpenGLWorker::FootageFrameToTexture(StreamPtr stream, FramePtr frame) const
|
||||
{
|
||||
FramePtr frame = decoder->RetrieveVideo(range.in(),
|
||||
video_params().divider());
|
||||
QVariant value;
|
||||
|
||||
NodeValue value;
|
||||
|
||||
if (frame) {
|
||||
QMetaObject::invokeMethod(proxy_,
|
||||
"FrameToValue",
|
||||
Qt::BlockingQueuedConnection,
|
||||
OLIVE_NS_RETURN_ARG(NodeValue, value),
|
||||
OLIVE_NS_ARG(FramePtr, frame),
|
||||
OLIVE_NS_ARG(StreamPtr, stream),
|
||||
OLIVE_NS_CONST_ARG(VideoParams&, video_params()),
|
||||
OLIVE_NS_CONST_ARG(RenderMode::Mode&, render_mode()));
|
||||
}
|
||||
QMetaObject::invokeMethod(proxy_,
|
||||
"FrameToValue",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(QVariant, value),
|
||||
OLIVE_NS_ARG(FramePtr, frame),
|
||||
OLIVE_NS_ARG(StreamPtr, stream),
|
||||
OLIVE_NS_CONST_ARG(VideoParams&, video_params()),
|
||||
OLIVE_NS_CONST_ARG(RenderMode::Mode&, render_mode()));
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void OpenGLWorker::ProcessNodeEvent(const Node *node, const TimeRange &range, NodeValueDatabase &input_params, NodeValueTable &output_params)
|
||||
QVariant OpenGLWorker::CachedFrameToTexture(FramePtr frame) const
|
||||
{
|
||||
RenderWorker::ProcessNodeEvent(node, range, input_params, output_params);
|
||||
QVariant value;
|
||||
|
||||
if (node->GetCapabilities(input_params) & Node::kShader) {
|
||||
QMetaObject::invokeMethod(proxy_,
|
||||
"RunNodeAccelerated",
|
||||
Qt::BlockingQueuedConnection,
|
||||
OLIVE_NS_CONST_ARG(Node*, node),
|
||||
OLIVE_NS_CONST_ARG(TimeRange&, range),
|
||||
OLIVE_NS_ARG(NodeValueDatabase&, input_params),
|
||||
OLIVE_NS_ARG(NodeValueTable&, output_params),
|
||||
OLIVE_NS_CONST_ARG(VideoParams&, video_params()));
|
||||
}
|
||||
QMetaObject::invokeMethod(proxy_,
|
||||
"PreCachedFrameToValue",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(QVariant, value),
|
||||
OLIVE_NS_ARG(FramePtr, frame));
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
QVariant OpenGLWorker::ProcessShader(const Node *node, const TimeRange &range, NodeValueDatabase &input_params)
|
||||
{
|
||||
QVariant value;
|
||||
|
||||
QMetaObject::invokeMethod(proxy_,
|
||||
"RunNodeAccelerated",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(QVariant, value),
|
||||
OLIVE_NS_CONST_ARG(Node*, node),
|
||||
OLIVE_NS_CONST_ARG(TimeRange&, range),
|
||||
OLIVE_NS_ARG(NodeValueDatabase&, input_params),
|
||||
OLIVE_NS_CONST_ARG(VideoParams&, video_params()));
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -34,9 +34,11 @@ public:
|
||||
protected:
|
||||
virtual void TextureToFrame(const QVariant& texture, FramePtr frame, const QMatrix4x4 &mat) const override;
|
||||
|
||||
virtual NodeValue FrameToTexture(DecoderPtr decoder, StreamPtr stream, const TimeRange &range) const override;
|
||||
virtual QVariant FootageFrameToTexture(StreamPtr stream, FramePtr frame) const override;
|
||||
|
||||
virtual void ProcessNodeEvent(const Node *node, const TimeRange &range, NodeValueDatabase &input_params, NodeValueTable &output_params) override;
|
||||
virtual QVariant CachedFrameToTexture(FramePtr frame) const override;
|
||||
|
||||
virtual QVariant ProcessShader(const Node *node, const TimeRange &range, NodeValueDatabase &input_params) override;
|
||||
|
||||
private:
|
||||
OpenGLProxy* proxy_;
|
||||
|
||||
@@ -382,7 +382,7 @@ void RenderBackend::CopyNodeInputValue(NodeInput *input)
|
||||
false);
|
||||
|
||||
// Handle connections
|
||||
if (input->IsConnected() || our_copy->IsConnected()) {
|
||||
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
|
||||
|
||||
@@ -444,7 +444,7 @@ Node* RenderBackend::CopyNodeConnections(Node* src_node)
|
||||
|
||||
void RenderBackend::CopyNodeMakeConnection(NodeInput* src_input, NodeInput* dst_input)
|
||||
{
|
||||
if (src_input->IsConnected()) {
|
||||
if (src_input->is_connected()) {
|
||||
Node* dst_node = CopyNodeConnections(src_input->get_connected_node());
|
||||
|
||||
NodeOutput* corresponding_output = dst_node->GetOutputWithID(src_input->get_connected_output()->id());
|
||||
|
||||
@@ -163,7 +163,7 @@ NodeValueTable RenderWorker::GenerateBlockTable(const TrackOutput *track, const
|
||||
}
|
||||
}
|
||||
|
||||
merged_table.Push(NodeParam::kSamples, QVariant::fromValue(block_range_buffer));
|
||||
merged_table.Push(NodeParam::kSamples, QVariant::fromValue(block_range_buffer), track);
|
||||
|
||||
return merged_table;
|
||||
|
||||
@@ -172,13 +172,8 @@ NodeValueTable RenderWorker::GenerateBlockTable(const TrackOutput *track, const
|
||||
}
|
||||
}
|
||||
|
||||
void RenderWorker::ProcessNodeEvent(const Node *node, const TimeRange &range, NodeValueDatabase &input_params_in, NodeValueTable &output_params)
|
||||
QVariant RenderWorker::ProcessSamples(const Node *node, const TimeRange &range, NodeValueDatabase &input_params_in)
|
||||
{
|
||||
// Check if node processes samples
|
||||
if (!(node->GetCapabilities(input_params_in) & Node::kSampleProcessor)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Copy database so we can make some temporary modifications to it
|
||||
NodeValueDatabase input_params = input_params_in;
|
||||
NodeInput* sample_input = node->ProcessesSamplesFrom(input_params);
|
||||
@@ -188,13 +183,13 @@ void RenderWorker::ProcessNodeEvent(const Node *node, const TimeRange &range, No
|
||||
|
||||
// If there isn't one, there's nothing to do
|
||||
if (samples_var.isNull()) {
|
||||
return;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
SampleBufferPtr input_buffer = samples_var.value<SampleBufferPtr>();
|
||||
|
||||
if (!input_buffer) {
|
||||
return;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
SampleBufferPtr output_buffer = SampleBuffer::CreateAllocated(input_buffer->audio_params(), input_buffer->sample_count());
|
||||
@@ -216,7 +211,7 @@ void RenderWorker::ProcessNodeEvent(const Node *node, const TimeRange &range, No
|
||||
NodeInput* input = static_cast<NodeInput*>(param);
|
||||
|
||||
// If the input isn't keyframing, we don't need to update it unless it's connected, in which case it may change
|
||||
if (input->IsConnected() || input->is_keyframing()) {
|
||||
if (input->is_connected() || input->is_keyframing()) {
|
||||
input_params.Insert(input, ProcessInput(input, TimeRange(this_sample_time, this_sample_time)));
|
||||
}
|
||||
}
|
||||
@@ -229,64 +224,85 @@ void RenderWorker::ProcessNodeEvent(const Node *node, const TimeRange &range, No
|
||||
i);
|
||||
}
|
||||
|
||||
output_params.Push(NodeParam::kSamples, QVariant::fromValue(output_buffer));
|
||||
return QVariant::fromValue(output_buffer);
|
||||
}
|
||||
|
||||
void RenderWorker::FootageProcessingEvent(StreamPtr stream, const TimeRange &input_time, NodeValueTable *table)
|
||||
void RenderWorker::ProcessNodeEvent(const Node *node, const TimeRange &range, NodeValueDatabase &input_params_in, NodeValueTable &output_params)
|
||||
{
|
||||
if (stream->type() == Stream::kVideo || stream->type() == Stream::kImage) {
|
||||
// Convert footage to image/sample buffers
|
||||
if (node->id() == QStringLiteral("org.olivevideoeditor.Olive.videoinput")) {
|
||||
QByteArray hash = RenderBackend::HashNode(node, video_params(), range.in());
|
||||
|
||||
ImageStreamPtr video_stream = std::static_pointer_cast<ImageStream>(stream);
|
||||
rational time_match = (stream->type() == Stream::kImage) ? rational() : input_time.in();
|
||||
QString colorspace_match = video_stream->get_colorspace_match_string();
|
||||
QString fn = FrameHashCache::CachePathName(hash, video_params_.format());
|
||||
|
||||
NodeValue value;
|
||||
bool found_cache = false;
|
||||
if (QFileInfo::exists(fn)) {
|
||||
FramePtr f = FrameHashCache::LoadCacheFrame(hash, video_params_.format());
|
||||
|
||||
if (still_image_cache_.contains(stream.get())) {
|
||||
const CachedStill& cs = still_image_cache_[stream.get()];
|
||||
QVariant cached = CachedFrameToTexture(f);
|
||||
|
||||
if (cs.colorspace == colorspace_match
|
||||
&& cs.alpha_is_associated == video_stream->premultiplied_alpha()
|
||||
&& cs.divider == video_params_.divider()
|
||||
&& cs.time == time_match) {
|
||||
value = cs.texture;
|
||||
found_cache = true;
|
||||
} else {
|
||||
still_image_cache_.remove(stream.get());
|
||||
if (!cached.isNull()) {
|
||||
output_params.Push(NodeParam::kTexture, cached, node);
|
||||
|
||||
// No more to do here
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found_cache) {
|
||||
QList<NodeInput*> inputs = node->GetInputsIncludingArrays();
|
||||
foreach (NodeInput* input, inputs) {
|
||||
if (input->data_type() == NodeParam::kFootage) {
|
||||
TimeRange input_time = node->InputTimeAdjustment(input, range);
|
||||
|
||||
value = GetDataFromStream(stream, input_time);
|
||||
StreamPtr stream = ResolveStreamFromInput(input);
|
||||
|
||||
still_image_cache_.insert(stream.get(), {value,
|
||||
colorspace_match,
|
||||
video_stream->premultiplied_alpha(),
|
||||
video_params_.divider(),
|
||||
time_match});
|
||||
if (stream) {
|
||||
QVariant v = ProcessFootage(stream, input_time);
|
||||
|
||||
if (!v.isNull()) {
|
||||
if (stream->type() == Stream::kVideo || stream->type() == Stream::kImage) {
|
||||
output_params.Push(NodeParam::kTexture, v, node);
|
||||
} else if (stream->type() == Stream::kAudio) {
|
||||
output_params.Push(NodeParam::kSamples, v, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
table->Push(value);
|
||||
// Check if node has a shader
|
||||
if (node->GetCapabilities(input_params_in) & Node::kShader) {
|
||||
QVariant v = ProcessShader(node, range, input_params_in);
|
||||
|
||||
} else if (stream->type() == Stream::kAudio) {
|
||||
if (!v.isNull()) {
|
||||
output_params.Push(NodeParam::kTexture, v, node);
|
||||
}
|
||||
}
|
||||
|
||||
table->Push(GetDataFromStream(stream, input_time));
|
||||
// Check if node processes samples
|
||||
if (node->GetCapabilities(input_params_in) & Node::kSampleProcessor) {
|
||||
QVariant v = ProcessSamples(node, range, input_params_in);
|
||||
|
||||
if (!v.isNull()) {
|
||||
output_params.Push(NodeParam::kSamples, v, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NodeValue RenderWorker::GetDataFromStream(StreamPtr stream, const TimeRange &input_time)
|
||||
QVariant RenderWorker::GetDataFromStream(StreamPtr stream, const TimeRange &input_time)
|
||||
{
|
||||
DecoderPtr decoder = ResolveDecoderFromInput(stream);
|
||||
|
||||
if (decoder) {
|
||||
if (stream->type() == Stream::kVideo || stream->type() == Stream::kImage) {
|
||||
|
||||
// Return a texture from the derived class
|
||||
return FrameToTexture(decoder, stream, input_time);
|
||||
FramePtr frame = decoder->RetrieveVideo(input_time.in(),
|
||||
video_params().divider());
|
||||
|
||||
if (frame) {
|
||||
// Return a texture from the derived class
|
||||
return FootageFrameToTexture(stream, frame);
|
||||
}
|
||||
|
||||
} else if (stream->type() == Stream::kAudio) {
|
||||
|
||||
@@ -334,13 +350,13 @@ NodeValue RenderWorker::GetDataFromStream(StreamPtr stream, const TimeRange &inp
|
||||
audio_params());
|
||||
|
||||
if (frame) {
|
||||
return NodeValue(NodeParam::kSamples, QVariant::fromValue(frame));
|
||||
return QVariant::fromValue(frame);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NodeValue();
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
DecoderPtr RenderWorker::ResolveDecoderFromInput(StreamPtr stream)
|
||||
@@ -366,4 +382,52 @@ DecoderPtr RenderWorker::ResolveDecoderFromInput(StreamPtr stream)
|
||||
return decoder;
|
||||
}
|
||||
|
||||
QVariant RenderWorker::ProcessFootage(StreamPtr stream, const TimeRange &input_time)
|
||||
{
|
||||
if (stream->type() == Stream::kVideo || stream->type() == Stream::kImage) {
|
||||
|
||||
ImageStreamPtr video_stream = std::static_pointer_cast<ImageStream>(stream);
|
||||
rational time_match = (stream->type() == Stream::kImage) ? rational() : input_time.in();
|
||||
QString colorspace_match = video_stream->get_colorspace_match_string();
|
||||
|
||||
QVariant value;
|
||||
bool found_cache = false;
|
||||
|
||||
if (still_image_cache_.contains(stream.get())) {
|
||||
const CachedStill& cs = still_image_cache_[stream.get()];
|
||||
|
||||
if (cs.colorspace == colorspace_match
|
||||
&& cs.alpha_is_associated == video_stream->premultiplied_alpha()
|
||||
&& cs.divider == video_params_.divider()
|
||||
&& cs.time == time_match) {
|
||||
value = cs.texture;
|
||||
found_cache = true;
|
||||
} else {
|
||||
still_image_cache_.remove(stream.get());
|
||||
}
|
||||
}
|
||||
|
||||
if (!found_cache) {
|
||||
|
||||
value = GetDataFromStream(stream, input_time);
|
||||
|
||||
still_image_cache_.insert(stream.get(), {value,
|
||||
colorspace_match,
|
||||
video_stream->premultiplied_alpha(),
|
||||
video_params_.divider(),
|
||||
time_match});
|
||||
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
} else if (stream->type() == Stream::kAudio) {
|
||||
|
||||
return GetDataFromStream(stream, input_time);
|
||||
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -114,14 +114,16 @@ public:
|
||||
protected:
|
||||
virtual void TextureToFrame(const QVariant& texture, FramePtr frame, const QMatrix4x4 &mat) const = 0;
|
||||
|
||||
virtual NodeValue FrameToTexture(DecoderPtr decoder, StreamPtr stream, const TimeRange &range) const = 0;
|
||||
virtual QVariant FootageFrameToTexture(StreamPtr stream, FramePtr frame) const = 0;
|
||||
|
||||
virtual void FootageProcessingEvent(StreamPtr stream, const TimeRange &input_time, NodeValueTable* table) override;
|
||||
virtual QVariant CachedFrameToTexture(FramePtr frame) const = 0;
|
||||
|
||||
virtual NodeValueTable GenerateBlockTable(const TrackOutput *track, const TimeRange &range) override;
|
||||
|
||||
virtual void ProcessNodeEvent(const Node *node, const TimeRange &range, NodeValueDatabase &input_params_in, NodeValueTable &output_params) override;
|
||||
|
||||
virtual QVariant ProcessShader(const Node *node, const TimeRange &range, NodeValueDatabase &input_params) = 0;
|
||||
|
||||
const VideoParams& video_params() const
|
||||
{
|
||||
return video_params_;
|
||||
@@ -146,10 +148,14 @@ signals:
|
||||
void WaveformGenerated(OLIVE_NAMESPACE::TrackOutput* track, OLIVE_NAMESPACE::AudioVisualWaveform samples, OLIVE_NAMESPACE::TimeRange start);
|
||||
|
||||
private:
|
||||
NodeValue GetDataFromStream(StreamPtr stream, const TimeRange& input_time);
|
||||
QVariant ProcessSamples(const Node *node, const TimeRange &range, NodeValueDatabase &input_params_in);
|
||||
|
||||
QVariant GetDataFromStream(StreamPtr stream, const TimeRange& input_time);
|
||||
|
||||
DecoderPtr ResolveDecoderFromInput(StreamPtr stream);
|
||||
|
||||
QVariant ProcessFootage(StreamPtr stream, const TimeRange &input_time);
|
||||
|
||||
RenderBackend* parent_;
|
||||
|
||||
VideoParams video_params_;
|
||||
@@ -157,7 +163,7 @@ private:
|
||||
AudioParams audio_params_;
|
||||
|
||||
struct CachedStill {
|
||||
NodeValue texture;
|
||||
QVariant texture;
|
||||
QString colorspace;
|
||||
bool alpha_is_associated;
|
||||
int divider;
|
||||
|
||||
Reference in New Issue
Block a user