mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-31 09:28:29 +00:00
pipeline: create shader-store pipelines at boot on half the hardware threads
This commit is contained in:
1 parent
14837b0479
commit
ec746622c2
3 files changed
+59
-17
No files matched your search
@@ -0,0 +1,35 @@
|
||||
#ifndef KYTY_COMMON_PARALLELFOR_H_
|
||||
#define KYTY_COMMON_PARALLELFOR_H_
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace Common {
|
||||
|
||||
// Half the hardware threads, at least one.
|
||||
inline size_t ParallelThreads() {
|
||||
return std::max(1u, std::thread::hardware_concurrency() / 2);
|
||||
}
|
||||
|
||||
// Calls job(i) for every i below count on up to ParallelThreads() threads, the caller included.
|
||||
template <typename Job>
|
||||
void ParallelFor(size_t count, const Job& job) {
|
||||
std::atomic_size_t next = 0;
|
||||
const auto work = [&] {
|
||||
for (auto i = next++; i < count; i = next++) {
|
||||
job(i);
|
||||
}
|
||||
};
|
||||
std::vector<std::jthread> helpers;
|
||||
for (auto i = std::min(count, ParallelThreads()); i > 1; i--) {
|
||||
helpers.emplace_back(work);
|
||||
}
|
||||
work();
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
|
||||
#endif // KYTY_COMMON_PARALLELFOR_H_
|
||||
Reference in new issue
Block a user