Merge pull request #15310 from unknownbrackets/softgpu-opt

softgpu: Tune queue push/pop to reduce overhead
This commit is contained in:
Henrik Rydgård 2022-01-16 09:38:45 +01:00 committed by GitHub
commit 86714d9f96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 9 deletions

View File

@ -105,8 +105,9 @@ public:
private:
void ProcessItems() {
while (!items_.Empty()) {
const BinItem item = items_.Pop();
const BinItem &item = items_.PeekNext();
DrawBinItem(item, states_[item.stateIndex]);
items_.SkipNext();
}
}
@ -261,12 +262,13 @@ void BinManager::Drain() {
if (taskRanges_.size() <= 1) {
while (!queue_.Empty()) {
const BinItem item = queue_.Pop();
const BinItem &item = queue_.PeekNext();
DrawBinItem(item, states_[item.stateIndex]);
queue_.SkipNext();
}
} else {
while (!queue_.Empty()) {
const BinItem item = queue_.Pop();
const BinItem &item = queue_.PeekNext();
for (int i = 0; i < (int)taskRanges_.size(); ++i) {
const BinCoords range = taskRanges_[i].Intersect(item.range);
if (range.Invalid())
@ -276,10 +278,13 @@ void BinManager::Drain() {
if (taskQueues_[i].Full())
waitable_->Wait();
BinItem subitem = item;
subitem.range = range;
taskQueues_[i].Push(subitem);
BinItem &taskItem = taskQueues_[i].PeekPush();
taskItem = item;
taskItem.range = range;
taskQueues_[i].PushPeeked();
}
queue_.SkipNext();
}
for (int i = 0; i < (int)taskRanges_.size(); ++i) {
@ -302,7 +307,7 @@ void BinManager::Flush() {
queue_.Reset();
while (states_.Size() > 1)
states_.Pop();
states_.SkipNext();
queueRange_.x1 = 0x7FFFFFFF;
queueRange_.y1 = 0x7FFFFFFF;

View File

@ -70,7 +70,7 @@ struct BinQueue {
}
size_t Push(const T &item) {
_dbg_assert_(size_ < N);
_dbg_assert_(size_ < N - 1);
size_t i = tail_++;
if (i + 1 == N)
tail_ -= N;
@ -89,12 +89,40 @@ struct BinQueue {
return item;
}
// Only safe if you're the only one reading.
T &PeekNext() {
_dbg_assert_(!Empty());
return items_[head_];
}
void SkipNext() {
_dbg_assert_(!Empty());
size_t i = head_++;
if (i + 1 == N)
head_ -= N;
size_--;
}
// Only safe if you're the only one writing.
T &PeekPush() {
_dbg_assert_(size_ < N - 1);
return items_[tail_];
}
void PushPeeked() {
_dbg_assert_(size_ < N - 1);
size_t i = tail_++;
if (i + 1 == N)
tail_ -= N;
size_++;
}
size_t Size() const {
return size_;
}
bool Full() const {
return size_ == N;
return size_ == N - 1;
}
bool Empty() const {