// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Core/Object.h"
#include "Engine/Core/NonCopyable.h"
#include "Engine/Core/Types/String.h"
#include "Engine/Threading/ConcurrentTaskQueue.h"
#include "GPUTask.h"
class GPUDevice;
class GPUResource;
class GPUTasksContext;
class GPUTasksExecutor;
///
/// Graphics Device work manager.
///
class GPUTasksManager : public Object, public NonCopyable
{
friend GPUDevice;
friend GPUTask;
private:
GPUDevice* _device;
GPUTasksExecutor* _executor;
ConcurrentTaskQueue _tasks;
Array _buffers[2];
int32 _bufferIndex;
private:
GPUTasksManager(GPUDevice* device);
~GPUTasksManager();
public:
///
/// Gets the parent Graphics Device.
///
/// The device.
FORCE_INLINE GPUDevice* GetDevice() const
{
return _device;
}
///
/// Gets the GPU tasks executor.
///
/// The tasks executor.
FORCE_INLINE GPUTasksExecutor* GetExecutor() const
{
return _executor;
}
///
/// Sets the GPU tasks executor.
///
/// The tasks executor.
void SetExecutor(GPUTasksExecutor* value);
///
/// Gets the amount of enqueued tasks to perform.
///
/// The tasks count.
FORCE_INLINE int32 GetTaskCount() const
{
return _tasks.Count();
}
public:
///
/// Clears asynchronous resources loading queue and cancels all tasks.
///
void Dispose();
public:
///
/// On begin rendering frame.
///
void FrameBegin();
///
/// On end rendering frame.
///
void FrameEnd();
public:
///
/// Requests work to do. Should be used only by GPUTasksExecutor.
///
/// The output buffer.
/// The maximum allowed amount of tasks to get.
/// The amount of tasks added to the buffer.
int32 RequestWork(GPUTask** buffer, int32 maxCount);
public:
// [Object]
String ToString() const override
{
return TEXT("GPU Tasks Manager");
}
};