softgpu: Avoid thread ordering hazard.

Must run the primitives in the right order.  No shortcutting allowed.
This commit is contained in:
Unknown W. Brackets 2022-01-13 23:03:24 -08:00
parent 970e9c2f51
commit dffc333120
3 changed files with 5 additions and 4 deletions

View file

@ -258,13 +258,13 @@ void ThreadManager::EnqueueTask(Task *task) {
chosenThread->cond.notify_one();
}
void ThreadManager::EnqueueTaskOnThread(int threadNum, Task *task) {
void ThreadManager::EnqueueTaskOnThread(int threadNum, Task *task, bool enforceSequence) {
_assert_msg_(threadNum >= 0 && threadNum < (int)global_->threads_.size(), "Bad threadnum or not initialized");
ThreadContext *thread = global_->threads_[threadNum];
// Try first atomically, as highest priority.
Task *expected = nullptr;
bool queued = thread->private_single.compare_exchange_weak(expected, task);
bool queued = !enforceSequence && thread->private_single.compare_exchange_weak(expected, task);
// Whether we got that or will have to wait, increase the queue counter.
thread->queue_size++;

View file

@ -46,7 +46,8 @@ public:
// just ignore it and let the OS handle it.
void Init(int numCores, int numLogicalCoresPerCpu);
void EnqueueTask(Task *task);
void EnqueueTaskOnThread(int threadNum, Task *task);
// Use enforceSequence if this must run after all previously queued tasks.
void EnqueueTaskOnThread(int threadNum, Task *task, bool enforceSequence = false);
void Teardown();
bool IsInitialized() const;

View file

@ -257,7 +257,7 @@ void BinManager::Drain() {
waitable_->Fill();
DrawBinItemTask *task = new DrawBinItemTask(waitable_, item, range, states_[item.stateIndex]);
g_threadManager.EnqueueTaskOnThread(i, task);
g_threadManager.EnqueueTaskOnThread(i, task, true);
}
}
}