// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
#pragma once
#include "../GPUContext.h"
#include "Engine/Platform/CriticalSection.h"
#include "Engine/Core/Collections/Array.h"
#include "GPUSyncPoint.h"
class GPUTask;
///
/// GPU tasks context
///
class GPUTasksContext
{
protected:
CriticalSection _locker;
GPUSyncPoint _currentSyncPoint;
Array _tasksDone;
int32 _totalTasksDoneCount;
public:
///
/// Initializes a new instance of the class.
///
/// The graphics device.
GPUTasksContext(GPUDevice* device);
///
/// Finalizes an instance of the class.
///
~GPUTasksContext();
public:
///
/// The GPU commands context used for tasks execution (can be only copy/upload without graphics capabilities on some platforms).
///
GPUContext* GPU;
public:
///
/// Gets graphics device handle
///
FORCE_INLINE GPUDevice* GetDevice() const
{
return GPU->GetDevice();
}
///
/// Gets current synchronization point of that context (CPU position, GPU has some latency)
///
FORCE_INLINE GPUSyncPoint GetCurrentSyncPoint() const
{
return _currentSyncPoint;
}
///
/// Gets total amount of tasks done by this context
///
FORCE_INLINE int32 GetTotalTasksDoneCount() const
{
return _totalTasksDoneCount;
}
///
/// Perform given task
///
/// Task to do
void Run(GPUTask* task);
void OnCancelSync(GPUTask* task);
public:
void OnFrameBegin();
void OnFrameEnd();
};