renderer: allow parameters to be changed mid-session

This commit is contained in:
itsmattkc
2020-01-22 14:05:37 +11:00
parent 8932a5abeb
commit fdbaa75dff
15 changed files with 118 additions and 32 deletions
+12 -2
View File
@@ -59,7 +59,7 @@ OpenGLTexturePtr OpenGLBackend::GetCachedFrameAsTexture(const rational &time)
{
const char* cached_frame = GetCachedFrame(time);
if (cached_frame != nullptr) {
if (cached_frame) {
master_texture_->Upload(cached_frame);
return master_texture_;
}
@@ -69,7 +69,7 @@ OpenGLTexturePtr OpenGLBackend::GetCachedFrameAsTexture(const rational &time)
bool OpenGLBackend::CompileInternal()
{
if (viewer_node() == nullptr || !viewer_node()->texture_input()->IsConnected()) {
if (!viewer_node() || !viewer_node()->texture_input()->IsConnected()) {
// Nothing to be done, nothing to compile
return true;
}
@@ -154,6 +154,16 @@ void OpenGLBackend::EmitCachedFrameReady(const rational &time, const QVariant &v
emit CachedFrameReady(time, QVariant::fromValue(tex), job_time);
}
void OpenGLBackend::ParamsChangedEvent()
{
// Assume if the texture is allocated, it needs to be changed. Otherwise the texture should be created through
// InitInternal() with the correct parameters
if (master_texture_) {
master_texture_->Destroy();
master_texture_->Create(QOpenGLContext::currentContext(), params().effective_width(), params().effective_height(), params().format());
}
}
OpenGLTexturePtr OpenGLBackend::CopyTexture(OpenGLTexturePtr input)
{
input->Lock();
@@ -30,6 +30,8 @@ protected:
virtual void EmitCachedFrameReady(const rational &time, const QVariant& value, qint64 job_time) override;
virtual void ParamsChangedEvent() override;
private:
OpenGLTexturePtr CopyTexture(OpenGLTexturePtr input);
+1 -1
View File
@@ -20,7 +20,7 @@ bool RenderBackend::Init()
return true;
}
threads_.resize(qMax(1, QThread::idealThreadCount() / 2));
threads_.resize(qMax(1, QThread::idealThreadCount() - 1));
for (int i=0;i<threads_.size();i++) {
QThread* thread = new QThread(this);
+16 -1
View File
@@ -44,7 +44,7 @@ VideoRenderBackend::VideoRenderBackend(QObject *parent) :
bool VideoRenderBackend::InitInternal()
{
cache_frame_load_buffer_.resize(PixelService::GetBufferSize(params_.format(), params_.effective_width(), params_.effective_height()));
ResizeCacheLoadBuffer();
return true;
}
@@ -84,6 +84,12 @@ void VideoRenderBackend::SetParameters(const VideoRenderingParams& params)
// Set new parameters
params_ = params;
// Resize frame load buffer
ResizeCacheLoadBuffer();
// Handle custom events from derivatives
ParamsChangedEvent();
// Set params on all processors
foreach (RenderWorker* worker, processors_) {
static_cast<VideoRenderWorker*>(worker)->SetParameters(params_);
@@ -162,6 +168,10 @@ void VideoRenderBackend::InvalidateCacheInternal(const rational &start_range, co
Requeue();
}
void VideoRenderBackend::ParamsChangedEvent()
{
}
VideoRenderFrameCache *VideoRenderBackend::frame_cache()
{
return &frame_cache_;
@@ -406,3 +416,8 @@ void VideoRenderBackend::Requeue()
CacheNext();
}
void VideoRenderBackend::ResizeCacheLoadBuffer()
{
cache_frame_load_buffer_.resize(PixelService::GetBufferSize(params_.format(), params_.effective_width(), params_.effective_height()));
}
+4
View File
@@ -105,6 +105,8 @@ protected:
virtual void InvalidateCacheInternal(const rational &start_range, const rational &end_range) override;
virtual void ParamsChangedEvent();
VideoRenderWorker::OperatingMode operating_mode_;
signals:
@@ -122,6 +124,8 @@ private:
void Requeue();
void ResizeCacheLoadBuffer();
VideoRenderingParams params_;
QByteArray cache_frame_load_buffer_;
+2 -2
View File
@@ -116,8 +116,8 @@ QString VideoRenderFrameCache::CachePathName(const QByteArray &hash, const Pixel
QString ext;
if (pix_fmt == PixelFormat::PIX_FMT_RGBA8) {
// For some reason, 8-bit EXRs are extremely slow to load, so we use TIFF instead.
if (pix_fmt == PixelFormat::PIX_FMT_RGBA8 || pix_fmt == PixelFormat::PIX_FMT_RGBA16U) {
// For some reason, integer EXRs are extremely slow to load, so we use TIFF instead.
ext = QStringLiteral("tiff");
} else {
ext = QStringLiteral("exr");
+10 -1
View File
@@ -187,6 +187,10 @@ void VideoRenderWorker::SetParameters(const VideoRenderingParams &video_params)
{
video_params_ = video_params;
if (IsStarted()) {
ResizeDownloadBuffer();
}
ParametersChangedEvent();
}
@@ -197,7 +201,7 @@ void VideoRenderWorker::SetOperatingMode(const VideoRenderWorker::OperatingMode
bool VideoRenderWorker::InitInternal()
{
download_buffer_.resize(PixelService::GetBufferSize(video_params().format(), video_params().effective_width(), video_params().effective_height()));
ResizeDownloadBuffer();
return true;
}
@@ -233,6 +237,11 @@ void VideoRenderWorker::Download(QVariant texture, QString filename)
}
}
void VideoRenderWorker::ResizeDownloadBuffer()
{
download_buffer_.resize(PixelService::GetBufferSize(video_params_.format(), video_params_.effective_width(), video_params_.effective_height()));
}
NodeValueTable VideoRenderWorker::RenderBlock(const TrackOutput *track, const TimeRange &range)
{
// A frame can only have one active block so we just validate the in point of the range
+2
View File
@@ -80,6 +80,8 @@ private:
void Download(QVariant texture, QString filename);
void ResizeDownloadBuffer();
VideoRenderingParams video_params_;
VideoRenderFrameCache* frame_cache_;
+19 -2
View File
@@ -27,8 +27,21 @@
#include "common/define.h"
#include "core.h"
PixelService::PixelService()
PixelService* PixelService::instance_ = nullptr;
void PixelService::CreateInstance()
{
instance_ = new PixelService();
}
void PixelService::DestroyInstance()
{
delete instance_;
}
PixelService *PixelService::instance()
{
return instance_;
}
PixelFormat::Format PixelService::GetConfiguredFormatForMode(RenderMode::Mode mode)
@@ -38,7 +51,11 @@ PixelFormat::Format PixelService::GetConfiguredFormatForMode(RenderMode::Mode mo
void PixelService::SetConfiguredFormatForMode(RenderMode::Mode mode, PixelFormat::Format format)
{
Core::SetPreferenceForRenderMode(mode, QStringLiteral("PixelFormat"), format);
if (format != GetConfiguredFormatForMode(mode)) {
Core::SetPreferenceForRenderMode(mode, QStringLiteral("PixelFormat"), format);
emit FormatChanged();
}
}
PixelFormat::Info PixelService::GetPixelFormatInfo(const PixelFormat::Format &format)
+16 -5
View File
@@ -27,16 +27,19 @@
#include "pixelformat.h"
#include "render/rendermodes.h"
class PixelService : public QObject {
class PixelService : public QObject
{
Q_OBJECT
public:
PixelService();
static void CreateInstance();
static void DestroyInstance();
static PixelService* instance();
/**
* @brief Returns the configured pixel format for a given mode
*/
static PixelFormat::Format GetConfiguredFormatForMode(RenderMode::Mode mode);
static void SetConfiguredFormatForMode(RenderMode::Mode mode, PixelFormat::Format format);
PixelFormat::Format GetConfiguredFormatForMode(RenderMode::Mode mode);
void SetConfiguredFormatForMode(RenderMode::Mode mode, PixelFormat::Format format);
/**
* @brief Return a PixelFormatInfo containing information for a certain format
@@ -88,6 +91,14 @@ public:
*/
static void ConvertRGBtoRGBA(FramePtr frame);
signals:
void FormatChanged();
private:
PixelService() = default;
static PixelService* instance_;
};
#endif // PIXELSERVICE_H