Skip to content

Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.

C++
1.9 KB
Raw Blame
#pragma once
#include <cstdint>
#include <deque>
#include <functional>
#include <thread>
#include <stdexcept>

namespace veyra::engine {
// All steps execute on the graph owner. Waiting is represented as a deadline,
// never a sleeping callback; each queued entry retains one batch lease.
class LiveGpuScheduler {
public:
    enum class State { Pending, Complete, Failed };
    struct Step {State state=State::Pending;int64_t wakeAt=0;};
    using Job=std::function<Step(int64_t)>;
    explicit LiveGpuScheduler():owner_(std::this_thread::get_id()){}
    LiveGpuScheduler(const LiveGpuScheduler&)=delete;
    LiveGpuScheduler& operator=(const LiveGpuScheduler&)=delete;
    ~LiveGpuScheduler(){cancel();}
    bool push(Job job,std::function<void()> finish){
        requireOwner();if(failed_||queue_.size()>=2)return false;
        queue_.push_back({std::move(job),std::move(finish)});return true;
    }
    void advance(int64_t now){
        requireOwner();wakeAt_=0;
        while(!queue_.empty()&&!failed_){
            Step result;
            try{result=queue_.front().job(now);}catch(...){result.state=State::Failed;}
            if(result.state==State::Pending){wakeAt_=result.wakeAt;break;}
            auto entry=std::move(queue_.front());queue_.pop_front();entry.finish();entry.job={};
            if(result.state==State::Failed){failed_=true;cancel();}
        }
    }
    void cancel(){requireOwner();while(!queue_.empty()){auto entry=std::move(queue_.front());queue_.pop_front();entry.finish();}wakeAt_=0;}
    uint32_t occupancy()const{return static_cast<uint32_t>(queue_.size());}
    bool failed()const{return failed_;}
    int64_t wakeAt()const{return wakeAt_;}
private:
    struct Entry {Job job;std::function<void()> finish;};
    void requireOwner()const{if(std::this_thread::get_id()!=owner_)throw std::logic_error("GPU scheduler called outside owner thread");}
    std::thread::id owner_;std::deque<Entry> queue_;bool failed_=false;int64_t wakeAt_=0;
};
}