Revert d3c49be80f and do it better
This commit is contained in:
@@ -58,8 +58,6 @@ protected:
|
||||
{
|
||||
}
|
||||
|
||||
~GPUTask();
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
/// Gets a task type.
|
||||
@@ -142,24 +140,5 @@ protected:
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnCancel() override
|
||||
{
|
||||
// Check if task is waiting for sync (very likely situation)
|
||||
if (IsSyncing())
|
||||
{
|
||||
// Task has been performed but is waiting for a CPU/GPU sync so we have to cancel that
|
||||
ASSERT(_context != nullptr);
|
||||
_context->OnCancelSync(this);
|
||||
_context = nullptr;
|
||||
SetState(TaskState::Canceled);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Maybe we could also handle cancel event during running but not yet syncing
|
||||
ASSERT(!IsRunning());
|
||||
}
|
||||
|
||||
// Base
|
||||
Task::OnCancel();
|
||||
}
|
||||
void OnCancel() override;
|
||||
};
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
#define GPU_TASKS_USE_DEDICATED_CONTEXT 0
|
||||
|
||||
GPUTasksContext::GPUTasksContext(GPUDevice* device)
|
||||
: _tasksDone(64)
|
||||
, _totalTasksDoneCount(0)
|
||||
{
|
||||
// Bump it up to prevent initial state problems with frame index comparison
|
||||
_currentSyncPoint = 10;
|
||||
@@ -30,8 +28,8 @@ GPUTasksContext::~GPUTasksContext()
|
||||
ASSERT(IsInMainThread());
|
||||
|
||||
// Cancel jobs to sync
|
||||
auto tasks = _tasksDone;
|
||||
_tasksDone.Clear();
|
||||
auto tasks = _tasksSyncing;
|
||||
_tasksSyncing.Clear();
|
||||
for (int32 i = 0; i < tasks.Count(); i++)
|
||||
{
|
||||
auto task = tasks[i];
|
||||
@@ -52,15 +50,16 @@ void GPUTasksContext::Run(GPUTask* task)
|
||||
{
|
||||
ASSERT(task != nullptr);
|
||||
|
||||
_tasksDone.Add(task);
|
||||
task->Execute(this);
|
||||
if (task->IsSyncing())
|
||||
_tasksSyncing.Add(task);
|
||||
}
|
||||
|
||||
void GPUTasksContext::OnCancelSync(GPUTask* task)
|
||||
{
|
||||
ASSERT(task != nullptr);
|
||||
|
||||
_tasksDone.Remove(task);
|
||||
_tasksSyncing.Remove(task);
|
||||
|
||||
if (!Engine::IsRequestingExit)
|
||||
LOG(Warning, "{0} has been canceled before a sync", task->ToString());
|
||||
@@ -76,9 +75,9 @@ void GPUTasksContext::OnFrameBegin()
|
||||
++_currentSyncPoint;
|
||||
|
||||
// Try to flush done jobs
|
||||
for (int32 i = 0; i < _tasksDone.Count(); i++)
|
||||
for (int32 i = 0; i < _tasksSyncing.Count(); i++)
|
||||
{
|
||||
auto task = _tasksDone[i];
|
||||
auto task = _tasksSyncing[i];
|
||||
auto state = task->GetState();
|
||||
if (task->GetSyncPoint() <= _currentSyncPoint && state != TaskState::Finished)
|
||||
{
|
||||
@@ -87,12 +86,12 @@ void GPUTasksContext::OnFrameBegin()
|
||||
}
|
||||
if (state == TaskState::Failed || state == TaskState::Canceled)
|
||||
{
|
||||
_tasksDone.RemoveAt(i);
|
||||
_tasksSyncing.RemoveAt(i);
|
||||
i--;
|
||||
}
|
||||
if (state == TaskState::Finished)
|
||||
{
|
||||
_tasksDone.RemoveAt(i);
|
||||
_tasksSyncing.RemoveAt(i);
|
||||
i--;
|
||||
_totalTasksDoneCount++;
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ class GPUTasksContext
|
||||
protected:
|
||||
CriticalSection _locker;
|
||||
GPUSyncPoint _currentSyncPoint;
|
||||
Array<GPUTask*> _tasksDone;
|
||||
int32 _totalTasksDoneCount;
|
||||
int32 _totalTasksDoneCount = 0;
|
||||
Array<GPUTask*, InlinedAllocation<64>> _tasksSyncing;
|
||||
|
||||
public:
|
||||
/// <summary>
|
||||
|
||||
@@ -7,16 +7,6 @@
|
||||
#include "Engine/Core/Types/String.h"
|
||||
#include "Engine/Graphics/GPUDevice.h"
|
||||
|
||||
GPUTask::~GPUTask()
|
||||
{
|
||||
// Ensure to dereference task
|
||||
if (auto context = _context)
|
||||
{
|
||||
_context = nullptr;
|
||||
context->OnCancelSync(this);
|
||||
}
|
||||
}
|
||||
|
||||
void GPUTask::Execute(GPUTasksContext* context)
|
||||
{
|
||||
ASSERT(IsQueued() && _context == nullptr);
|
||||
@@ -58,6 +48,21 @@ void GPUTask::Enqueue()
|
||||
GPUDevice::Instance->GetTasksManager()->_tasks.Add(this);
|
||||
}
|
||||
|
||||
void GPUTask::OnCancel()
|
||||
{
|
||||
// Check if task is waiting for sync (very likely situation)
|
||||
if (IsSyncing())
|
||||
{
|
||||
// Task has been performed but is waiting for a CPU/GPU sync so we have to cancel that
|
||||
ASSERT(_context != nullptr);
|
||||
_context->OnCancelSync(this);
|
||||
_context = nullptr;
|
||||
}
|
||||
|
||||
// Base
|
||||
Task::OnCancel();
|
||||
}
|
||||
|
||||
GPUTasksManager::GPUTasksManager()
|
||||
{
|
||||
_buffers[0].EnsureCapacity(64);
|
||||
|
||||
Reference in New Issue
Block a user