// Copyright (c) 2012-2023 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:
GPUTasksExecutor* _executor = nullptr;
ConcurrentTaskQueue _tasks;
Array _buffers[2];
int32 _bufferIndex = 0;
public:
GPUTasksManager();
///
/// Gets the GPU 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.
///
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;
};