softgpu: Use persistent bin task state.

It's constant, so it's better to avoid the copying and allocation.  A
small win, but removes new from the profile.
This commit is contained in:
Unknown W. Brackets committed 2022-01-20 16:58:43 -08:00
1 parent 3e4d768e7a
commit 55c11425e4
4 files changed
+31 -5

No files matched your search

+2 -2
View File
@@ -105,7 +105,7 @@ bool ThreadManager::TeardownTask(Task *task, bool enqueue) {
if (task->Cancellable()) {
task->Cancel();
delete task;
task->Release();
return true;
}
@@ -174,7 +174,7 @@ static void WorkerThreadFunc(GlobalThreadContext *global, ThreadContext *thread)
// responsibility of the ThreadManager (although it could be!).
if (task) {
task->Run();
delete task;
task->Release();
// Reduce the queue size once complete.
thread->queue_size--;
+1
View File
@@ -19,6 +19,7 @@ public:
virtual bool Cancellable() { return false; }
virtual void Cancel() {}
virtual uint64_t id() { return 0; }
virtual void Release() { delete this; }
};
class Waitable {
+14 -3
View File
@@ -105,6 +105,10 @@ public:
notify_->Drain();
}
void Release() override {
// Don't delete, this is statically allocated.
}
private:
void ProcessItems() {
while (!items_.Empty()) {
@@ -131,8 +135,11 @@ BinManager::BinManager() {
s = false;
int maxInitTasks = std::min(g_threadManager.GetNumLooperThreads(), MAX_POSSIBLE_TASKS);
for (int i = 0; i < maxInitTasks; ++i)
for (int i = 0; i < maxInitTasks; ++i) {
taskQueues_[i].Setup();
for (DrawBinItemsTask *&task : taskLists_[i].tasks)
task = new DrawBinItemsTask(waitable_, taskQueues_[i], taskStatus_[i], states_);
}
states_.Setup();
cluts_.Setup();
queue_.Setup();
@@ -140,6 +147,11 @@ BinManager::BinManager() {
BinManager::~BinManager() {
delete waitable_;
for (int i = 0; i < MAX_POSSIBLE_TASKS; ++i) {
for (DrawBinItemsTask *task : taskLists_[i].tasks)
delete task;
}
}
void BinManager::UpdateState() {
@@ -335,8 +347,7 @@ void BinManager::Drain() {
waitable_->Fill();
taskStatus_[i] = true;
DrawBinItemsTask *task = new DrawBinItemsTask(waitable_, taskQueues_[i], taskStatus_[i], states_);
g_threadManager.EnqueueTaskOnThread(i, task, true);
g_threadManager.EnqueueTaskOnThread(i, taskLists_[i].Next(), true);
enqueues_++;
}
+14
View File
@@ -152,6 +152,19 @@ union BinClut {
uint8_t readable[1024];
};
struct BinTaskList {
// We shouldn't ever need more than two at once, since we use an atomic to run one at a time.
// A second could run due to overlap during teardown.
static constexpr int N = 2;
DrawBinItemsTask *tasks[N]{};
int count = 0;
DrawBinItemsTask *Next() {
return tasks[count % N];
}
};
class BinManager {
public:
BinManager();
@@ -204,6 +217,7 @@ private:
bool tasksSplit_ = false;
std::vector<BinCoords> taskRanges_;
BinItemQueue taskQueues_[MAX_POSSIBLE_TASKS];
BinTaskList taskLists_[MAX_POSSIBLE_TASKS];
std::atomic<bool> taskStatus_[MAX_POSSIBLE_TASKS];
BinWaitable *waitable_ = nullptr;