Fix GPU Tasks queue to be executed on frame start, rather than end
This commit is contained in:
@@ -23,19 +23,18 @@ void DefaultGPUTasksExecutor::FrameBegin()
|
||||
_context = createContext();
|
||||
|
||||
_context->OnFrameBegin();
|
||||
}
|
||||
|
||||
void DefaultGPUTasksExecutor::FrameEnd()
|
||||
{
|
||||
ASSERT(_context != nullptr);
|
||||
|
||||
// Default implementation performs async operations on end of the frame which is synchronized with a rendering thread
|
||||
// Default implementation performs async operations on start of the frame which is synchronized with a rendering thread
|
||||
GPUTask* buffer[32];
|
||||
const int32 count = GPUDevice::Instance->GetTasksManager()->RequestWork(buffer, 32);
|
||||
for (int32 i = 0; i < count; i++)
|
||||
{
|
||||
_context->Run(buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void DefaultGPUTasksExecutor::FrameEnd()
|
||||
{
|
||||
ASSERT(_context != nullptr);
|
||||
_context->OnFrameEnd();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public:
|
||||
/// <summary>
|
||||
/// Describes GPU work type
|
||||
/// </summary>
|
||||
DECLARE_ENUM_4(Type, Custom, CopyResource, UploadTexture, UploadBuffer);
|
||||
DECLARE_ENUM_EX_4(Type, byte, 0, Custom, CopyResource, UploadTexture, UploadBuffer);
|
||||
|
||||
/// <summary>
|
||||
/// Describes GPU work result value
|
||||
@@ -32,13 +32,15 @@ private:
|
||||
/// </summary>
|
||||
Type _type;
|
||||
|
||||
byte _syncLatency;
|
||||
|
||||
/// <summary>
|
||||
/// Synchronization point when async task has been done
|
||||
/// </summary>
|
||||
GPUSyncPoint _syncPoint;
|
||||
|
||||
/// <summary>
|
||||
/// The context that performed this task, it's should synchronize it.
|
||||
/// The context that performed this task, it should synchronize it.
|
||||
/// </summary>
|
||||
GPUTasksContext* _context;
|
||||
|
||||
@@ -47,8 +49,10 @@ protected:
|
||||
/// Initializes a new instance of the <see cref="GPUTask"/> class.
|
||||
/// </summary>
|
||||
/// <param name="type">The type.</param>
|
||||
GPUTask(const Type type)
|
||||
/// <param name="syncLatency">Amount of frames until async operation is synced with GPU.</param>
|
||||
GPUTask(const Type type, byte syncLatency = GPU_ASYNC_LATENCY)
|
||||
: _type(type)
|
||||
, _syncLatency(syncLatency)
|
||||
, _syncPoint(0)
|
||||
, _context(nullptr)
|
||||
{
|
||||
@@ -58,7 +62,6 @@ public:
|
||||
/// <summary>
|
||||
/// Gets a task type.
|
||||
/// </summary>
|
||||
/// <returns>The type.</returns>
|
||||
FORCE_INLINE Type GetType() const
|
||||
{
|
||||
return _type;
|
||||
@@ -67,17 +70,15 @@ public:
|
||||
/// <summary>
|
||||
/// Gets work finish synchronization point
|
||||
/// </summary>
|
||||
/// <returns>Finish task sync point</returns>
|
||||
FORCE_INLINE GPUSyncPoint GetSyncPoint() const
|
||||
{
|
||||
return _syncPoint;
|
||||
return _syncPoint + _syncLatency;
|
||||
}
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Checks if operation is syncing
|
||||
/// </summary>
|
||||
/// <returns>True if operation is syncing, otherwise false</returns>
|
||||
FORCE_INLINE bool IsSyncing() const
|
||||
{
|
||||
return IsRunning() && _syncPoint != 0;
|
||||
|
||||
@@ -70,16 +70,16 @@ void GPUTasksContext::OnFrameBegin()
|
||||
++_currentSyncPoint;
|
||||
|
||||
// Try to flush done jobs
|
||||
auto currentSyncPointGPU = _currentSyncPoint - GPU_ASYNC_LATENCY;
|
||||
for (int32 i = 0; i < _tasksDone.Count(); i++)
|
||||
{
|
||||
if (_tasksDone[i]->GetSyncPoint() <= currentSyncPointGPU)
|
||||
auto task = _tasksDone[i];
|
||||
if (task->GetSyncPoint() <= _currentSyncPoint && task->GetState() != TaskState::Finished)
|
||||
{
|
||||
// TODO: add stats counter and count performed jobs, print to log on exit.
|
||||
|
||||
auto job = _tasksDone[i];
|
||||
job->Sync();
|
||||
|
||||
task->Sync();
|
||||
}
|
||||
if (task->GetState() == TaskState::Finished)
|
||||
{
|
||||
_tasksDone.RemoveAt(i);
|
||||
i--;
|
||||
_totalTasksDoneCount++;
|
||||
|
||||
@@ -42,7 +42,6 @@ public:
|
||||
/// <summary>
|
||||
/// Gets graphics device handle
|
||||
/// </summary>
|
||||
/// <returns>Graphics device</returns>
|
||||
FORCE_INLINE GPUDevice* GetDevice() const
|
||||
{
|
||||
return GPU->GetDevice();
|
||||
@@ -51,7 +50,6 @@ public:
|
||||
/// <summary>
|
||||
/// Gets current synchronization point of that context (CPU position, GPU has some latency)
|
||||
/// </summary>
|
||||
/// <returns>Context sync point</returns>
|
||||
FORCE_INLINE GPUSyncPoint GetCurrentSyncPoint() const
|
||||
{
|
||||
return _currentSyncPoint;
|
||||
@@ -60,7 +58,6 @@ public:
|
||||
/// <summary>
|
||||
/// Gets total amount of tasks done by this context
|
||||
/// </summary>
|
||||
/// <returns>Done tasks count</returns>
|
||||
FORCE_INLINE int32 GetTotalTasksDoneCount() const
|
||||
{
|
||||
return _totalTasksDoneCount;
|
||||
|
||||
@@ -30,6 +30,11 @@ void GPUTask::Execute(GPUTasksContext* context)
|
||||
// Save task completion point (for synchronization)
|
||||
_syncPoint = context->GetCurrentSyncPoint();
|
||||
_context = context;
|
||||
if (_syncLatency == 0)
|
||||
{
|
||||
// No delay on sync
|
||||
Sync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user