some render cache adjustments

This commit is contained in:
itsmattkc
2019-09-04 10:58:50 +10:00
parent 12bc5839a6
commit 371d0e2b37
22 changed files with 150 additions and 48 deletions
+11 -10
View File
@@ -36,8 +36,7 @@ RendererProcessor::RendererProcessor() :
width_(0),
height_(0),
divider_(1),
caching_(false),
last_requested_time_(-1)
caching_(false)
{
texture_input_ = new NodeInput("tex_in");
texture_input_->add_data_input(NodeInput::kTexture);
@@ -79,8 +78,6 @@ void RendererProcessor::SetCacheName(const QString &s)
QVariant RendererProcessor::Value(NodeOutput* output, const rational& time)
{
if (output == texture_output_) {
last_requested_time_ = time;
if (!texture_input_->IsConnected()) {
// Nothing is connected - nothing to show or render
return 0;
@@ -98,7 +95,6 @@ QVariant RendererProcessor::Value(NodeOutput* output, const rational& time)
// Find frame in map
if (time_hash_map_.contains(time)) {
qDebug() << "Showed:" << time_hash_map_[time].toHex();
QString fn = CachePathName(time_hash_map_[time]);
@@ -340,6 +336,11 @@ void RendererProcessor::ThreadCallback()
time_hash_map_.insert(cache_frame_, master_thread_->hash());
// We didn't receive a texture to download, but the viewer may still need updating
if (texture == nullptr) {
DownloadThreadFinished(cache_frame_);
}
CacheNext();
}
}
@@ -357,15 +358,15 @@ void RendererProcessor::ThreadRequestSibling(NodeDependency dep)
void RendererProcessor::DownloadThreadFinished(const rational& time)
{
// Check if we just downloaded (akak finished caching) the frame we're currently on
if (texture_output_->IsConnected() && time == last_requested_time_) {
if (texture_output_->IsConnected()) {
if (texture_output_->LastRequestedTime() == time) {
texture_output_->ClearCachedValue();
}
// Send invalidate cache signal to all nodes connected to the texture output
QVector<NodeEdgePtr> edges = texture_output()->edges();
texture_output_->ClearCachedValue();
foreach (NodeEdgePtr edge, edges) {
edge->input()->ClearCachedValue();
edge->input()->parent()->InvalidateCache(time,
time,
edge->input());
-2
View File
@@ -176,8 +176,6 @@ private:
QVector<RendererDownloadThreadPtr> download_threads_;
int last_download_thread_;
rational last_requested_time_;
RenderTexturePtr master_texture_;
QMap<rational, QByteArray> time_hash_map_;
@@ -12,7 +12,8 @@ RendererDownloadThread::RendererDownloadThread(QOpenGLContext *share_ctx,
const int &height,
const olive::PixelFormat &format,
const olive::RenderMode &mode) :
RendererThreadBase(share_ctx, width, height, format, mode)
RendererThreadBase(share_ctx, width, height, format, mode),
cancelled_(false)
{
}
@@ -29,6 +30,17 @@ void RendererDownloadThread::Queue(RenderTexturePtr texture, const QString& fn,
texture_queue_lock_.unlock();
}
void RendererDownloadThread::Cancel()
{
cancelled_ = true;
texture_queue_lock_.lock();
wait_cond_.wakeAll();
texture_queue_lock_.unlock();
wait();
}
void RendererDownloadThread::ProcessLoop()
{
QOpenGLFunctions* f = render_instance()->context()->functions();
@@ -53,13 +65,21 @@ void RendererDownloadThread::ProcessLoop()
OIIO::ImageSpec spec(render_instance()->width(), render_instance()->height(), kRGBAChannels, format_info.oiio_desc);
spec.attribute("compression", "dwaa:200");
while (!Cancelled()) {
while (!cancelled_) {
// Check queue for textures to download (use mutex to prevent collisions)
texture_queue_lock_.lock();
while (texture_queue_.isEmpty()) {
// Main waiting condition
wait_cond_.wait(&texture_queue_lock_);
if (cancelled_) {
break;
}
}
if (cancelled_) {
texture_queue_lock_.unlock();
break;
}
working_texture = texture_queue_.takeFirst();
@@ -15,6 +15,9 @@ public:
void Queue(RenderTexturePtr texture, const QString &fn, const rational &time);
public slots:
virtual void Cancel() override;
signals:
void Downloaded(const rational& time);
@@ -32,6 +35,8 @@ private:
QMutex texture_queue_lock_;
QAtomicInt cancelled_;
};
using RendererDownloadThreadPtr = std::shared_ptr<RendererDownloadThread>;
@@ -29,7 +29,8 @@ RendererProcessThread::RendererProcessThread(RendererProcessor* parent,
const olive::PixelFormat &format,
const olive::RenderMode &mode) :
RendererThreadBase(share_ctx, width, height, format, mode),
parent_(parent)
parent_(parent),
cancelled_(false)
{
}
@@ -70,12 +71,27 @@ RenderTexturePtr RendererProcessThread::texture()
return texture_;
}
void RendererProcessThread::Cancel()
{
cancelled_ = true;
mutex_.lock();
wait_cond_.wakeAll();
mutex_.unlock();
wait();
}
void RendererProcessThread::ProcessLoop()
{
while (!Cancelled()) {
while (!cancelled_) {
// Main waiting condition
wait_cond_.wait(&mutex_);
if (cancelled_) {
break;
}
// Wake up main thread
caller_mutex_.lock();
wait_cond_.wakeAll();
@@ -42,6 +42,9 @@ public:
RenderTexturePtr texture();
public slots:
virtual void Cancel() override;
protected:
virtual void ProcessLoop() override;
@@ -61,6 +64,8 @@ private:
RenderTexturePtr texture_;
QAtomicInt cancelled_;
};
using RendererProcessThreadPtr = std::shared_ptr<RendererProcessThread>;
@@ -24,7 +24,6 @@
RendererThreadBase::RendererThreadBase(QOpenGLContext *share_ctx, const int &width, const int &height, const olive::PixelFormat &format, const olive::RenderMode &mode) :
share_ctx_(share_ctx),
cancelled_(false),
width_(width),
height_(height),
format_(format),
@@ -34,15 +33,6 @@ RendererThreadBase::RendererThreadBase(QOpenGLContext *share_ctx, const int &wid
connect(share_ctx_, SIGNAL(aboutToBeDestroyed()), this, SLOT(Cancel()));
}
void RendererThreadBase::Cancel()
{
// Escape main loop
cancelled_ = true;
// Wait until thread is finished before returning
wait();
}
RenderInstance *RendererThreadBase::render_instance()
{
return render_instance_;
@@ -79,11 +69,6 @@ void RendererThreadBase::run()
mutex_.unlock();
}
bool RendererThreadBase::Cancelled()
{
return cancelled_;
}
void RendererThreadBase::StartThread(QThread::Priority priority)
{
caller_mutex_.lock();
@@ -46,13 +46,11 @@ public:
virtual void run() override;
public slots:
void Cancel();
virtual void Cancel() = 0;
protected:
virtual void ProcessLoop() = 0;
bool Cancelled();
QWaitCondition wait_cond_;
QMutex mutex_;
@@ -62,8 +60,6 @@ protected:
private:
QOpenGLContext* share_ctx_;
bool cancelled_;
const int& width_;
const int& height_;