mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-22 07:01:30 +00:00
[idd] transport: fan out frame publication
This commit is contained in:
@@ -25,81 +25,147 @@
|
||||
#include "transport/IFrameTransport.h"
|
||||
#include "transport/ITransport.h"
|
||||
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
class CFrameHub final : public IFrameTransport
|
||||
{
|
||||
private:
|
||||
static const unsigned MAX_SLOTS = 1024;
|
||||
|
||||
struct Slot
|
||||
struct Sink
|
||||
{
|
||||
uint64_t serial = 0;
|
||||
bool committed = false;
|
||||
bool completionPending = false;
|
||||
bool completionSucceeded = false;
|
||||
struct ResourceLane
|
||||
{
|
||||
uint8_t * mem = nullptr;
|
||||
uint64_t heapOffset = 0;
|
||||
unsigned localSlot = 0;
|
||||
bool direct = false;
|
||||
bool valid = false;
|
||||
bool busy = false;
|
||||
};
|
||||
|
||||
CSRWLock callLock;
|
||||
IFrameSink * target = nullptr;
|
||||
HANDLE drained = nullptr;
|
||||
std::atomic<unsigned> outstanding = 0;
|
||||
std::atomic_bool active = false;
|
||||
std::atomic<BackendId> backend = 0;
|
||||
std::atomic<uint32_t> epoch = 0;
|
||||
bool reserved = false;
|
||||
bool primary = false;
|
||||
bool needsFullCopy = true;
|
||||
uint64_t lastContent = 0;
|
||||
uint64_t blockedContent = 0;
|
||||
size_t blockedFrameSize = 0;
|
||||
bool blockedAllocation = false;
|
||||
unsigned pitch = 0;
|
||||
unsigned width = 0;
|
||||
unsigned height = 0;
|
||||
DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;
|
||||
FrameType frameType = FRAME_TYPE_INVALID;
|
||||
ResourceLane lanes[FRAME_SINK_BUFFERS] = {};
|
||||
};
|
||||
|
||||
mutable CSRWLock m_lock;
|
||||
IFrameSink * m_sink = nullptr;
|
||||
BackendId m_backend = 0;
|
||||
uint32_t m_epoch = 0;
|
||||
uint64_t m_nextSerial = 0;
|
||||
std::vector<Slot> m_slots;
|
||||
struct BatchTarget
|
||||
{
|
||||
Sink * sink = nullptr;
|
||||
BackendId backend = 0;
|
||||
uint32_t epoch = 0;
|
||||
unsigned localSlot = 0;
|
||||
unsigned resourceLane = 0;
|
||||
CFrameScheduler::Schedule schedule = {};
|
||||
CFrameScheduler::Schedule deliverySchedule = {};
|
||||
uint64_t content = 0;
|
||||
unsigned pitch = 0;
|
||||
unsigned width = 0;
|
||||
unsigned height = 0;
|
||||
DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;
|
||||
FrameType frameType = FRAME_TYPE_INVALID;
|
||||
bool periodic = false;
|
||||
bool published = false;
|
||||
bool delivered = false;
|
||||
bool submitted = false;
|
||||
bool committed = false;
|
||||
bool completionPending = false;
|
||||
bool completionSucceeded = false;
|
||||
bool releasePending = false;
|
||||
bool active = false;
|
||||
};
|
||||
|
||||
bool Valid(const FrameToken& token) const;
|
||||
void Invalidate(const FrameToken& token);
|
||||
struct Batch
|
||||
{
|
||||
CSRWLock lock;
|
||||
uint64_t serial = 0;
|
||||
unsigned count = 0;
|
||||
bool active = false;
|
||||
BatchTarget targets[FRAME_MAX_SINKS] = {};
|
||||
};
|
||||
|
||||
struct SinkRef
|
||||
{
|
||||
Sink * sink;
|
||||
unsigned index;
|
||||
bool primary;
|
||||
};
|
||||
|
||||
mutable CSRWLock m_listLock;
|
||||
Sink m_sinks[FRAME_MAX_SINKS];
|
||||
Batch m_batches[FRAME_BATCHES];
|
||||
std::atomic<uint64_t> m_nextSerial = 0;
|
||||
std::atomic<uint64_t> m_nextContent = 0;
|
||||
std::atomic<uint64_t> m_newestContent = 0;
|
||||
HANDLE m_wakeEvent = nullptr;
|
||||
|
||||
unsigned Snapshot(SinkRef refs[FRAME_MAX_SINKS]) const;
|
||||
bool BatchValid(const Batch& batch, const FrameBatchToken& token) const;
|
||||
void ReleaseTarget(Batch& batch, BatchTarget& target);
|
||||
void CompleteTarget(Batch& batch, BatchTarget& target, bool succeeded);
|
||||
|
||||
public:
|
||||
bool Bind(BackendId backend, uint32_t epoch, IFrameSink& sink);
|
||||
CFrameHub();
|
||||
~CFrameHub() override;
|
||||
|
||||
CFrameHub(const CFrameHub&) = delete;
|
||||
CFrameHub& operator=(const CFrameHub&) = delete;
|
||||
|
||||
bool Bind(BackendId backend, uint32_t epoch, bool primary,
|
||||
IFrameSink& sink);
|
||||
void Unbind(BackendId backend, uint32_t epoch);
|
||||
|
||||
size_t GetMaxFrameSize() const override;
|
||||
bool FrameBufferAvailable(const CFrameScheduler::Schedule& schedule,
|
||||
bool allowReadyReplacement = true) override;
|
||||
bool HasPublishedFrame() const override;
|
||||
void ProcessDeliveries() override;
|
||||
bool GetPendingDeliveryTarget(uint64_t now, uint64_t& target) override;
|
||||
bool RetryPendingDelivery(uint64_t now, bool& retry) override;
|
||||
PreparedFrameBuffer PrepareFrameBuffer(unsigned pitch,
|
||||
uint64_t NextContentSerial() override;
|
||||
void FrameProductReady(uint64_t contentSerial) override;
|
||||
bool NeedsFrame() const override;
|
||||
bool GetFramePlan(
|
||||
uint64_t now, bool productReady, FramePlan& plan) override;
|
||||
bool GetImmediateFramePlan(
|
||||
uint64_t now, FramePlan& plan) override;
|
||||
void MissFramePlan(const FramePlan& plan, uint64_t now) override;
|
||||
bool PrepareFrameBatch(const FramePlan& plan,
|
||||
uint64_t contentSerial, unsigned pitch, size_t frameSize,
|
||||
const D12FrameFormat& srcFormat, const D12FrameFormat& dstFormat,
|
||||
const RECT * dirtyRects, unsigned nbDirtyRects,
|
||||
const CFrameScheduler::Schedule& schedule,
|
||||
bool allowReadyReplacement = true) override;
|
||||
bool PublishFrameBuffer(const FrameToken& token,
|
||||
const CFrameScheduler::Schedule& schedule,
|
||||
bool& deliveredToOwner) override;
|
||||
bool RepublishFrameBuffer(
|
||||
const CFrameScheduler::Schedule& schedule) override;
|
||||
bool TryFrameSubmitted(const FrameToken& token,
|
||||
const CFrameScheduler::Schedule& schedule) override;
|
||||
void CommitFrameBuffer(const FrameToken& token,
|
||||
const CFrameScheduler::Schedule& schedule, bool periodic,
|
||||
bool deliveredToOwner) override;
|
||||
void AbortFrameBuffer(const FrameToken& token) override;
|
||||
void FailFrameBuffer(const FrameToken& token) override;
|
||||
void CompleteFrameBuffer(
|
||||
const FrameToken& token, bool succeeded) override;
|
||||
void SetFrameTiming(const FrameToken& token, uint64_t captureTime,
|
||||
uint64_t postProcessTime, uint64_t copyTime, uint64_t readyTime,
|
||||
uint64_t holdTime, const CFrameScheduler::Schedule& schedule,
|
||||
bool allowReadyReplacement, PreparedFrameBatch& batch) override;
|
||||
uint32_t PublishFrameBatch(const FrameBatchToken& token) override;
|
||||
void CommitFrameBatch(const FrameBatchToken& token) override;
|
||||
void AbortFrameBatch(const FrameBatchToken& token) override;
|
||||
void FailFrameBatch(const FrameBatchToken& token) override;
|
||||
void WriteFrameTarget(const FrameBatchToken& token,
|
||||
unsigned target, void * src, size_t offset, size_t len,
|
||||
bool setWritePos) const override;
|
||||
void WriteFrameTargetRows(const FrameBatchToken& token,
|
||||
unsigned target, void * src, size_t offset, size_t rowBytes,
|
||||
size_t pitch, unsigned rows) const override;
|
||||
void FinalizeFrameTarget(const FrameBatchToken& token,
|
||||
unsigned target) const override;
|
||||
void SetFrameTargetTiming(const FrameBatchToken& token,
|
||||
unsigned target, uint64_t captureTime, uint64_t postProcessTime,
|
||||
uint64_t copyTime, uint64_t readyTime, uint64_t holdTime,
|
||||
uint64_t completedAt) override;
|
||||
void WriteFrameBuffer(const FrameToken& token, void * src,
|
||||
size_t offset, size_t len, bool setWritePos) const override;
|
||||
void WriteFrameBufferRows(const FrameToken& token, void * src,
|
||||
size_t offset, size_t rowBytes, size_t pitch,
|
||||
unsigned rows) const override;
|
||||
void FinalizeFrameBuffer(const FrameToken& token) const override;
|
||||
|
||||
void TryRecordFrameTiming(const FrameBatchToken& token,
|
||||
unsigned target, uint64_t duration) override;
|
||||
void CompleteFrameTarget(const FrameBatchToken& token,
|
||||
unsigned target, bool succeeded) override;
|
||||
void ObserveFrame(uint64_t now) override;
|
||||
void ForceFrame() override;
|
||||
bool GetPublishTarget(uint64_t now, uint64_t& target,
|
||||
CFrameScheduler::Schedule& schedule, bool& periodic,
|
||||
bool& republish) override;
|
||||
void FrameMissed(const CFrameScheduler::Schedule& schedule,
|
||||
uint64_t now, bool periodic) override;
|
||||
void FrameSuperseded() override;
|
||||
HANDLE GetFrameScheduleEvent() const override;
|
||||
void TryRecordFrameTiming(
|
||||
const FrameToken& token, uint64_t duration) override;
|
||||
HANDLE GetFrameScheduleEvent() const override { return m_wakeEvent; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user